What is updateGeometricState() and when do I need it?
UpdateGeometricState() 方法的用处,什么时候用?
In jme3 it is more important than in jme2 that the correct updating and rendering order is kept, this is why you should understand what updateGeometricState() is all about.
在 jme3 中有了很重要的跟新,渲染序列可控性也大大提高,所以到处都会用到 updateGeometricState() 这个方法,你必须对这个方法有深刻的理解。
What does updateGeometricState() do?
updateGeometricState () 用来做什么。
The call to updateGeometricState() applies all changes made to a Spatials location , rotation and scale and computes the correct world position including the Spatials parent position (if there is one) so all information is correct for the rendering process. When updateGeometricState() is called on a Node, all child Spatials will be updated as well, given that their flags indicate something has changed. In a normal update loop, updateGeometricState() is called once on the Scenes rootNode just before rendering.
updateGeometricState() 会在三维空间中应用所有的更改,包括:位置、旋转、缩放以及纠正所有父级别的三维空间坐标,所以此时所有的信息都会在渲染线程中纠正。当 updateGeometricState() 在一个节点上被调用时,所有的子空间将被更新,并且给他们的标志标记上已经改变的记录,通常的跟新循环中该方法只在场景的根节点开始渲染前调用一次。
Why would you want to use updateGeometricState() yourself then?
为什么你有时候想要来使用 updateGeometricState() 方法?
Since the world location of spatials is only known after updateGeometricState() has been called in jme2 , it was common practice for some to call updateGeometricState() on the spatial to compute its correct location because it had been changed before. In jme3 you should not do that as updateGeometricState() should only be called once on the rootNode of the scene during the update loop. If you really have to updateGeometric(), do so on the rootNode. In some tests however, especially physics tests, you might see that updateGeometricState() is used on created PhysicsNodes. This is however before they are added to a rootNode that is part of a live scene. When a Spatial has a parent or was added to the root node, do not call updateGeometricState() on it.
由于在 jme2 中场景空间对象的世界坐标 只有在 updateGeometricState() 被调用后才能知道,在空间对象上调用 updateGeometricState() 来计算正确的世界坐标在空间中的位置是常用的做法,因为它之前已经被改变了。 在 jme3 中你可以不用那么做, updateGeometricState() 仅仅在每次循环中只在根节点上调用一次。如果你趋势有必要去调用 updateGeometric() ,那就在根节点上调用。然而在一些练习中,尤其是物理检测中你可能会看到 updateGeometric() 在被创建的物理节点上被使用,这是由于在它们成为活动场景的一部分之前需要计算它(物理节点)的位置。当一个三维空间对象有一个父节点或者已经被添加到了根节点,请不要调用 updateGeometric() 。
When to change a Spatials translation
当发生了空间对象的转换
So going along this logic, you should not change the Spatials translation after updateGeometricState() has been called anymore. So how or when do you change it? Before. :) The InputListeners for example are called before updateGeometricState() is called on the rootNode and the Spatials are in their correct, updated state from the last loop run. Now you can use setLocalTranslation etc. to modify your Spatials, also using translation info from the other Spatials. The controllers (updateLogicalState()) are the second chance to modify your Spatials, they are used by the animation and particle systems for example. If you absolutely need to read the world location of a spatial in your normal update() call, you should call updateGeometricState() once on the root Node of the scene and read the world locations after that.
依照这个逻辑,你不应该在调用了 updateGeometricState() 之后再去做一些空间对象的变换。那么什么时候或者怎么才能进行变换呢?首先一个输入监听器被一个实例在根节点调用 updateGeometricState() 之前被调用并且空间对象已经处于它们的正确位置,在循环的最后更新状态。现在你可以使用 setLocalTranslation ()或其他的方法来修改你的空间对象,同样可以从其他的空间对象使用变换信息。控制器()会马上对你的空间对象作出修改,它们被动画和粒子系统使用。如果你绝对需要在你的 update() 中得到一个空间对象的世界坐标,你可以在根节点上调用一次 updateGeometricState() 之后来读取世界坐标。
《这篇文章字不多,给我搞的云里雾里的,效果很不好,请高手指点一下。。。》