Hi! I had a problem when working with Away3d.
After loading some models (say, 3DS) with transformation matrices and displaying them on the screen, the lighting did not work correctly (there was no diffuse light), because wrong calculated vertices normals (and tangents). Moreover, the problem is relevant when HTML5 is used; under the Flash everything worked correctly. After a few hours of searching, I found that when transforming the geometry, normals (and tangents) of vertices are transformed using the Matrix3D.deltaTransformVector, but this function is not performed equally in the flash and in the openfl, so all the normals are shifted somewhere during the transformation.
So, i think in Matrix3D.deltaTransformVector instead of
return new Vector3D ((x * rawData  + y * rawData  + z * rawData  + rawData ), (x * rawData  + y * rawData  + z * rawData  + rawData ), (x * rawData  + y * rawData  + z * rawData  + rawData , 0);
in openfl, there is another calculations in Flash:
Return new Vector3D ((x * rawData  + y * rawData  + z * rawData ), (x * rawData  + y * rawData  + z * rawData ), (x * rawData  + y * rawData  + z * rawData ), (x * rawData  + y * rawData  + z * rawData ));
Now everything works correctly after fixing this function for openfl, it’s just an information, i think it must be fixed in openfl
Sorry for my english!
Does this fix it for you?
It’s similar to your change, but the
w property is set to zero.
The documentation suggests the translation should be ignored (like your fix) and
w should be zero (like this fix)
Thanks, yes, it work’s fine now. I think w=0 will be ok for all cases, but just need to say, that internal Flash deltaTransformVector function returns
w=x * rawData + y * rawData + z * rawData
as i can see from my tests with this function. Anyway, “w” result of this function is never used in away3d and i don’t think it will be used anywhere else
Huh, strange! The documentation says:
Note: This method automatically sets the w component of the passed Vector3D to 0.0.
Do you have any code handy that we could add to our unit tests, to confirm the behavior of the method? Don’t worry about having actual asserts, but just some quick
mat = new Matrix3D (),
mat.deltaTransformVector and the expected values of the returned
I don’t have Haxe right now I have Flash CS6, so in order not to wait for the morning, i can test it, but in pure AS3 (in haxe result was the same, of course):
var v:Vector.<Number> = new Vector.<Number>();
for (var i:int = 0; i < 16; i++)
var a:Vector3D = new Vector3D(1,2,3,4);
var b:Matrix3D = new Matrix3D(v);
var c:Vector3D = b.deltaTransformVector(a);
38 44 50 56
Thanks! I’ve added both your original code, plus your code sample as a unit test.
I realize now, the documentation must mean that the
w of the incoming vector is ignored. I guess. Either way, same behavior in Flash Player and in HTML5 now, and that’s what counts for this
Yes, that’s it, it works the same as transformVector, but with forcing w=0 in incoming vector.