SCNRender scene with animated objects

I have SCNScene with animated objects (.dae files), as well as SCNRender , with initialization of openGLContext . When I set the animation scene to this render, I do not see the animation, but when I set the animation scene to SCNView , I see the animation.

How to install Render:

self.renderer = [SCNRenderer rendererWithContext:_openGLContext options:nil]; self.renderer.autoenablesDefaultLighting = YES; self.renderer.playing = YES; self.renderer.scene = myAnimatedScene; 

I understand that OpenGL can only draw objects, it knows nothing about the animation settings in my .dae file

Can someone explain to me how I can draw an animated scene using SCNRender initialized with openGLContext ?

+5
source share
1 answer

It looks like when calling the following function:

 renderer.render(atTime: time, viewport: viewport, commandBuffer: commandBuffer, passDescriptor: renderPassDescriptor) 

the time parameter is really important. Before I left it with zero and there were no animations. If you set it using CFAbsoluteTimeGetCurrent (), it seems that you can only get one animation (I just tested it). My game hero has an action for shooting, as well as walking, and setting atTime with CFAbsoluteTimeGetCurrent () only appears walking.)

However, our situations are slightly different. In my case, I also have a SCNView that displays the perspectives of the hero. Therefore, to run all the animations, I created a globe variable:

 var globeTime:TimeInterval = 0 

And saved the current time in the SCNView rendering function:

 func renderer(_ aRenderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { globeTime = time //... } 

And finally passed it to my SCNRender.

 //... renderer.render(atTime: globeTime, viewport: viewport, commandBuffer: commandBuffer, passDescriptor: renderPassDescriptor) 

This solved my problem perfectly.

0
source

Source: https://habr.com/ru/post/1259152/


All Articles