I tried to scale an object alongside a specific dimension with the set_matrix function from the transform module in Blend4Web.
Here is an example matrix applied by
a 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
a be 0.1
Expectation: It should be scaled to 0.1 on X.
Result: It was scaled down approximately 0.8 on X, Y and Z.
Left is the original cube, the right is transformed with the matrix as defined above.
then I assigned different values to
a, and find many anomalies, the two most noticeable:
- The transformation is not linear,
- and happens on all 3D axes. (it should be carried out only on X)
The funniest case when
a is zero, because in this setting the transformation matrix spans only to 2 dimensions, which should collapse the cube to a square... well it makes it a slightly smaller cube, but at least it collapsed my mind to the null space.
I made a self contained example in a project, you can extract it into your project folder. This reproduces what I described, the only difference that it changes 2 basis vectors to null vector instead of one.
I changed two things on the default Blend4Web starter file:
- Reseted the cube transformation to the identity. (it is translated on Z by 1 on default scene )
- turned on the physics on the cube object, so it can be transformed.
var cube = m_scenes.get_object_by_name("cube"); // The cube object on default b4w scene is transformed by the identity. var mat = m_trans.get_matrix(cube); // Create a global function to update the cube transformation matrix // from the inspector. updateMatfromWindow(mat, cube); console.log("identity: "); mat4_pprint(mat); mat = 0; mat = 0; console.log('collapsing to one dimension'); mat4_pprint(mat); /** * after this the cube should disaper. since it transformed by a matrix with a * zero determinant. */ m_trans.set_matrix(cube, mat);
I also added some extra features for testing, so you can update the transformation matrix of the cube from the inspector, using the
updateMat(ind, val), function, for example:
updateMat(12, 1) // will translate the cube 1 unit on x.
and a matrix pretty printer function.
- NixOS 17.09 “Hummingbird” (GNU/Linux)
- Blender 2.79a
- Blend4Web 17.12.0