diff --git a/core/src/avm2/globals/flash/display/display_object.rs b/core/src/avm2/globals/flash/display/display_object.rs index 92f8737b269e..4b79847dfd91 100644 --- a/core/src/avm2/globals/flash/display/display_object.rs +++ b/core/src/avm2/globals/flash/display/display_object.rs @@ -750,25 +750,37 @@ pub fn set_transform<'gc>( ) -> Result, Error<'gc>> { let transform = args.get_object(activation, 0, "transform")?; - // FIXME - consider 3D matrix and pixel bounds - let matrix = transform - .get_public_property("matrix", activation)? - .as_object(); - - let Some(matrix) = matrix else { - // FP seems to not do anything when setting to a Transform with a null matrix, - // but we don't actually support setting the matrix to null anyway - // (see the comment in `flash::geom::transform::set_matrix`) - return Ok(Value::Undefined); + // FIXME - consider pixel bounds + let (matrix, mode_3d) = { + if let Some(matrix3d) = transform + .get_public_property("matrix3D", activation)? + .as_object() + { + let matrix3d = crate::avm2::globals::flash::geom::transform::object_to_matrix3d( + matrix3d, activation, + )?; + // FIXME: 3D transformation is unsupported now. + let matrix = Matrix::from(matrix3d); + (matrix, true) + } else if let Some(matrix) = transform + .get_public_property("matrix", activation)? + .as_object() + { + let matrix = + crate::avm2::globals::flash::geom::transform::object_to_matrix(matrix, activation)?; + (matrix, false) + } else { + // FP seems to not do anything when setting to a Transform with a null matrix, + // but we don't actually support setting the matrix to null anyway + // (see the comment in `flash::geom::transform::set_matrix`) + return Ok(Value::Undefined); + } }; let color_transform = transform .get_public_property("colorTransform", activation)? .as_object() .expect("colorTransform should be non-null"); - - let matrix = - crate::avm2::globals::flash::geom::transform::object_to_matrix(matrix, activation)?; let color_transform = crate::avm2::globals::flash::geom::transform::object_to_color_transform( color_transform, activation, @@ -778,6 +790,7 @@ pub fn set_transform<'gc>( let mut write = dobj.base_mut(activation.context.gc_context); write.set_matrix(matrix); write.set_color_transform(color_transform); + write.set_mode_3d(mode_3d); drop(write); if let Some(parent) = dobj.parent() { // Self-transform changes are automatically handled, diff --git a/core/src/avm2/globals/flash/geom/transform.rs b/core/src/avm2/globals/flash/geom/transform.rs index 9de88c37ffbc..9201ebd7e1b1 100644 --- a/core/src/avm2/globals/flash/geom/transform.rs +++ b/core/src/avm2/globals/flash/geom/transform.rs @@ -243,7 +243,7 @@ fn matrix3d_to_object<'gc>( Ok(object.into()) } -fn object_to_matrix3d<'gc>( +pub fn object_to_matrix3d<'gc>( object: Object<'gc>, activation: &mut Activation<'_, 'gc>, ) -> Result> { diff --git a/tests/tests/swfs/avm2/geom_transform/Test.as b/tests/tests/swfs/avm2/geom_transform/Test.as index 850b2266a0da..844db36354ed 100644 --- a/tests/tests/swfs/avm2/geom_transform/Test.as +++ b/tests/tests/swfs/avm2/geom_transform/Test.as @@ -17,9 +17,8 @@ package { testCopy2D(); trace(""); - //// FIXME: transformation copy is unsupported now. - // testCopy3D(); - // trace(""); + testCopy3D(); + trace(""); testImageComparison(); } @@ -83,26 +82,24 @@ package { trace("sprite2.transform.matrix3D", sprite2.transform.matrix3D); } - //// FIXME - // private function testCopy3D() : void { - // var sprite1 : Sprite = new Sprite(); - // var sprite2 : Sprite = new Sprite(); - // - // trace("// Copy3D"); - // var mat3D : Matrix3D = new Matrix3D(); - // mat3D.appendRotation(1, Vector3D.Z_AXIS); - // mat3D.appendScale(2, 3, 4); - // mat3D.appendTranslation(5, 6, 7); - // sprite1.transform.matrix3D = mat3D; - // sprite2.transform = sprite1.transform; - // trace("sprite1.transform.matrix", sprite1.transform.matrix); - // trace("sprite1.transform.matrix3D", sprite1.transform.matrix3D); - // trace("sprite1.transform.matrix3D.rawData", sprite1.transform.matrix3D.rawData); - // trace("sprite2.transform.matrix", sprite2.transform.matrix); - // trace("sprite2.transform.matrix3D", sprite2.transform.matrix3D); - // trace("sprite2.transform.matrix3D.rawData", sprite2.transform.matrix3D.rawData); - // } + private function testCopy3D() : void { + var sprite1 : Sprite = new Sprite(); + var sprite2 : Sprite = new Sprite(); + trace("// Copy3D"); + var mat3D : Matrix3D = new Matrix3D(); + mat3D.appendRotation(1, Vector3D.Z_AXIS); + mat3D.appendScale(2, 3, 1); // FIXME: zScale shouldn't be one (1) for test coverage. Unsupported now. + mat3D.appendTranslation(5, 6, 0); // FIXME: z shouldn't be zero (0) for test coverage. Unsupported now. + sprite1.transform.matrix3D = mat3D; + sprite2.transform = sprite1.transform; + trace("sprite1.transform.matrix", sprite1.transform.matrix); + trace("sprite1.transform.matrix3D", sprite1.transform.matrix3D); + trace("sprite1.transform.matrix3D.rawData", sprite1.transform.matrix3D.rawData); + trace("sprite2.transform.matrix", sprite2.transform.matrix); + trace("sprite2.transform.matrix3D", sprite2.transform.matrix3D); + trace("sprite2.transform.matrix3D.rawData", sprite2.transform.matrix3D.rawData); + } private function testImageComparison() : void { var m : Matrix3D = new Matrix3D(); diff --git a/tests/tests/swfs/avm2/geom_transform/output.txt b/tests/tests/swfs/avm2/geom_transform/output.txt index 2455e3e6bfa9..026a92ab726f 100644 --- a/tests/tests/swfs/avm2/geom_transform/output.txt +++ b/tests/tests/swfs/avm2/geom_transform/output.txt @@ -22,3 +22,11 @@ sprite1.transform.matrix3D null sprite2.transform.matrix (a=1, b=2, c=3, d=4, tx=5, ty=6) sprite2.transform.matrix3D null +// Copy3D +sprite1.transform.matrix null +sprite1.transform.matrix3D [object Matrix3D] +sprite1.transform.matrix3D.rawData 1.9996954202651978,0.05235721915960312,0,0,-0.03490481153130531,2.9995431900024414,0,0,0,0,1,0,5,6,0,1 +sprite2.transform.matrix null +sprite2.transform.matrix3D [object Matrix3D] +sprite2.transform.matrix3D.rawData 1.9996954202651978,0.05235721915960312,0,0,-0.03490481153130531,2.9995431900024414,0,0,0,0,1,0,5,6,0,1 + diff --git a/tests/tests/swfs/avm2/geom_transform/test.swf b/tests/tests/swfs/avm2/geom_transform/test.swf index ae49d7394ebe..fafd0a4bb4b2 100644 Binary files a/tests/tests/swfs/avm2/geom_transform/test.swf and b/tests/tests/swfs/avm2/geom_transform/test.swf differ