@@ -3,10 +3,14 @@ import {
33 combine ,
44 GltfLoader ,
55 RuntimeModelInstancingPipelineStage ,
6+ ModelInstancesUpdateStage ,
67 Math as CesiumMath ,
8+ Buffer ,
9+ BufferUsage ,
710 ModelStatistics ,
811 Resource ,
912 ResourceCache ,
13+ SceneMode ,
1014 ShaderBuilder ,
1115 ModelInstance ,
1216 Transforms ,
@@ -94,6 +98,7 @@ describe(
9498 } ,
9599 runtimeNode : {
96100 node : node ,
101+ children : [ ] ,
97102 } ,
98103 } ;
99104 }
@@ -190,6 +195,95 @@ describe(
190195 }
191196 } ) ;
192197 } ) ;
198+
199+ it ( "model instances update stage updates transform vertex attributes" , function ( ) {
200+ return loadGltf ( sampleGltfUrl ) . then ( function ( gltfLoader ) {
201+ const components = gltfLoader . components ;
202+ const node = components . nodes [ 0 ] ;
203+ const renderResources = mockRenderResources ( node ) ;
204+ const runtimeNode = renderResources . runtimeNode ;
205+ const sceneGraph = renderResources . model . sceneGraph ;
206+
207+ scene . renderForSpecs ( ) ;
208+ RuntimeModelInstancingPipelineStage . process (
209+ renderResources ,
210+ node ,
211+ scene . frameState ,
212+ ) ;
213+
214+ const context = scene . frameState . context ;
215+ const usage = BufferUsage . STATIC_DRAW ;
216+
217+ const expectedTransformsTypedArray = new Float32Array ( [
218+ - 0.410076379776001 , 0.7071067690849304 , 0.576053261756897 , 0 ,
219+ - 0.410076379776001 , - 0.7071067690849304 , 0.576053261756897 , 0 ,
220+ 0.8146623373031616 , 0 , 0.5799355506896973 , 0 , 0 , 0 , 0 , 10 , 10 , 10 ,
221+ - 0.410076379776001 , 0.7071067690849304 , 0.576053261756897 , 0 ,
222+ - 0.410076379776001 , - 0.7071067690849304 , 0.576053261756897 , 0 ,
223+ 0.8146623373031616 , 0 , 0.5799355506896973 , 0 , 0 , 0 , 0 , 20 , 20 , 20 ,
224+ ] ) ;
225+
226+ const expectedTransformsBuffer = Buffer . createVertexBuffer ( {
227+ context,
228+ usage,
229+ typedArray : expectedTransformsTypedArray ,
230+ } ) ;
231+ expect ( runtimeNode . instancingTransformsBuffer . _buffer ) . toEqual (
232+ expectedTransformsBuffer . _buffer ,
233+ ) ;
234+
235+ const samplePosition3 = new Cartesian3 ( 30 , 30 , 30 ) ;
236+ const samplePosition4 = new Cartesian3 ( 40 , 40 , 40 ) ;
237+
238+ const instanceModelMatrix3 =
239+ new Transforms . headingPitchRollToFixedFrame (
240+ samplePosition3 ,
241+ headingPositionRoll ,
242+ Ellipsoid . WGS84 ,
243+ fixedFrameTransform ,
244+ ) ;
245+
246+ const instanceModelMatrix4 =
247+ new Transforms . headingPitchRollToFixedFrame (
248+ samplePosition4 ,
249+ headingPositionRoll ,
250+ Ellipsoid . WGS84 ,
251+ fixedFrameTransform ,
252+ ) ;
253+
254+ const sampleInstance3 = new ModelInstance ( instanceModelMatrix3 ) ;
255+ const sampleInstance4 = new ModelInstance ( instanceModelMatrix4 ) ;
256+
257+ sceneGraph . modelInstances = [ sampleInstance3 , sampleInstance4 ] ;
258+ runtimeNode . _apiInstancesDirty = true ;
259+
260+ const frameState = {
261+ mode : SceneMode . SCENE3D ,
262+ } ;
263+
264+ ModelInstancesUpdateStage . update ( runtimeNode , sceneGraph , frameState ) ;
265+
266+ const newExpectedTransformsTypedArray = new Float32Array ( [
267+ - 0.410076379776001 , 0.7071067690849304 , 0.576053261756897 , 0 ,
268+ - 0.410076379776001 , - 0.7071067690849304 , 0.576053261756897 , 0 ,
269+ 0.8146623373031616 , 0 , 0.5799355506896973 , 0 , 0 , 0 , 0 , 30 , 30 , 30 ,
270+ - 0.410076379776001 , 0.7071067690849304 , 0.576053261756897 , 0 ,
271+ - 0.410076379776001 , - 0.7071067690849304 , 0.576053261756897 , 0 ,
272+ 0.8146623373031616 , 0 , 0.5799355506896973 , 0 , 0 , 0 , 0 , 40 , 40 , 40 ,
273+ ] ) ;
274+
275+ const newExpectedTransformsBuffer = Buffer . createVertexBuffer ( {
276+ context,
277+ usage,
278+ typedArray : newExpectedTransformsTypedArray ,
279+ } ) ;
280+
281+ expect ( runtimeNode . _apiInstancesDirty ) . toBeFalse ( ) ;
282+ expect ( runtimeNode . instancingTransformsBuffer . _buffer ) . toEqual (
283+ newExpectedTransformsBuffer . _buffer ,
284+ ) ;
285+ } ) ;
286+ } ) ;
193287 } ,
194288 "WebGL" ,
195289) ;
0 commit comments