Skip to content

Commit

Permalink
avm2: Support matrix3D in transform copy
Browse files Browse the repository at this point in the history
  • Loading branch information
cookie-s committed Dec 7, 2024
1 parent b879581 commit ac547ca
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 36 deletions.
39 changes: 26 additions & 13 deletions core/src/avm2/globals/flash/display/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,25 +750,37 @@ pub fn set_transform<'gc>(
) -> Result<Value<'gc>, 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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm2/globals/flash/geom/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Matrix3D, Error<'gc>> {
Expand Down
41 changes: 19 additions & 22 deletions tests/tests/swfs/avm2/geom_transform/Test.as
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ package {
testCopy2D();
trace("");

//// FIXME: transformation copy is unsupported now.
// testCopy3D();
// trace("");
testCopy3D();
trace("");

testImageComparison();
}
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions tests/tests/swfs/avm2/geom_transform/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Binary file modified tests/tests/swfs/avm2/geom_transform/test.swf
Binary file not shown.

0 comments on commit ac547ca

Please sign in to comment.