Comments (5)
Hello and thank you for your report!
This is not a bug: if you don't set the forceUpdate argument to true, ISceneNode.getWorldToLocalTransform() will return the matrix computed to the last batched update.
Now the fact that you add a new mesh will tell the TransformController that the transforms list has to be invalidated. If you don't set forceUpdate to true, the list is indeed rebuilt but the values are not init.
So if you just do:
var m2:Matrix4x4 = camera.getWorldToLocalTransform(true);
It should work fine.
One might argue that invalidating the transforms list should always force an update.
We could also avoid init. this list with blank values and use the existing ones when they make sense.
This is debatable.
Regards,
from minko.
forceUpdate in every call will lead to huge calculations overhead and everything will slowdown to the 2.1 version. And what's the profit of new TransformController in this case?
It seems it must do calculations only when it is necessary.
And I don't understand how adding a new object to scene changing camera's WorldToLocal ?
from minko.
forceUpdate in every call will lead to huge calculations overhead and everything will slowdown
No: forceUpdate will tell the TransformController to attempt to update the localToWorld of the node.
As you can see in TransformController.updateAncestorsAndSelfLocalToWorld(), we find the "dirtyRoot" of the sub-scene of the node first. If nothing is "dirty", nothing gets updated.
So if you call camera.getWorldToLocalTransform(true) twice (or more) in a row, the second call will do nothing but try to find that dirty root. And that operation's complexity depends on the height of the tree, so it's likely to be painless.
this.timer = new Timer(1000);
Using a timer actually makes it harder for you to see what happens here I guess. If you simply try to get the localToWorld from a node right after it has been added to the scene, you'll notice that it's the identity matrix except when you use forceUpdate = true.
But as you're using a timer here, some frames get rendered before you call camera.getLocalToWorldTransform(). Therefore, as frames get rendered, the localToWorld of the camera is updated by the TransformController and it's perfectly logic it has the right value when you try to read it in your timer.
But that's because the Scene.renderingBegin signal triggered the batched update of the TransformController and hides the fact that the computations are done in a lazy fashion. Always.
And what's the profit of new TransformController in this case?
If the localToWorld doesn't change after you read it then the TransformController will not update it when Scene.renderingBegin is executed. So the TransformController really doesn't do the same computation twice ever.
I don't understand how adding a new object to scene changing camera's WorldToLocal ?
It doesn't.
But adding new objects to a (sub)scene will require to re-build the list of localToWorld transforms stored in the TransformController. Indeed: in order to provide the best performances for a batched update, the controller stores the hierarchy of transforms as a breadth first list. In 99% of the cases, updating this list is less efficient than simply re-building it.
That's where the debatable part is: when this list is built, localToWorld values are init. with the identity matrix. Why ? Because that's how we do it for now :) But again, using forceUpdate = true will update that matrix anyway and it won't cause re-computation if that transform doesn't change afterward. Again this is a choice - a debatable one - but a choice, not a bug or a glitch since it's the expected behavior.
Now, I agree this behavior is neither efficient nor intuitive. Therefore, I've changed TransformController.updateTransformsList() to use the "old" values if they exist:
I think this should work without any problem and would give you the result you expected.
Please confirm.
But the localToWorld of the Mesh you add between those two camera.getWorldToLocalTransform() will still be the identity matrix has long as you don't call getLocalToWorld(true) or a frame gets rendered: that's the whole point of "lazy" computations.
Regards,
from minko.
Please confirm
yes, work without problem.
Next bugreport :)
package {
import aerys.minko.render.geometry.primitive.CubeGeometry;
import aerys.minko.scene.node.Mesh;
import aerys.minko.type.math.Vector4;
import flash.events.Event;
public class Main extends MinkoExampleApplication {
override protected function initializeScene() : void {
super.initializeScene();
scene.addChild(new Mesh(CubeGeometry.cubeGeometry));
_lookAt = new Vector4();
_position = new Vector4();
}
override protected function enterFrameHandler(event : Event) : void
{
rotateX += 0.01;
_position.set(
_lookAt.x + 5 * Math.sin(rotateX),
_lookAt.y + 5 * Math.cos(rotateX),
_lookAt.z
);
camera.transform.lookAt(_lookAt, _position, Vector4.Y_AXIS);
// camera.getWorldToLocalTransform(true);
super.enterFrameHandler(event);
}
private var rotateX:Number = 0;
private var _lookAt:Vector4;
private var _position:Vector4;
}
}
At this example, camera rotating around cube.
If uncomment "camera.getWorldToLocalTransform(true);", camera will stop rotating.
from minko.
please push this in another issue so that we can mark it as a bug (if relevant) and make sure we can track it properly
thank you!
from minko.
Related Issues (20)
- where is minko shaderlab and shaderStudio HOT 5
- minko compile 1 error generated HOT 3
- Collision detection HOT 5
- when will you provide minko3 flash version? HOT 1
- Vulkan API HOT 1
- README Linux section is confuse HOT 2
- Collada model picking? HOT 11
- Chinese characters cannot display on minko-plugin-html-overlay HOT 3
- Mouse events unusable on MacBook HOT 1
- Integration with UIKit HOT 1
- Invalid NDK Path
- Compile Minko SDK android HOT 4
- CylinderGeometry HOT 1
- Using a webserver in the compiled application for an html overlay
- Has minko been abandaned by original developers? HOT 7
- I want use haxe to reimplement the minko source code. HOT 2
- haxe to reimplement the minko source code. HOT 2
- Android build instructions out of date HOT 1
- Integration into Qt HOT 2
- Any chance of enabling discussions on this repo?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minko.