Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avm2: Implement flash.geom.PerspectiveProjection #19532

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cookie-s
Copy link
Contributor

@cookie-s cookie-s commented Feb 16, 2025

doc: https://docs.ruffle.rs/en_US/FlashPlatform/reference/actionscript/3/flash/geom/PerspectiveProjection.html

This PR implements flash.geom.PerspectiveProjection features. However, assignment to flash.display.DisplayObject through transform.perspectiveProjection is not yet supported. No effect to visual, either.

@cookie-s cookie-s force-pushed the avm2-perspective-projection branch 3 times, most recently from 21ae2a2 to de64c8d Compare February 16, 2025 02:15
@cookie-s cookie-s marked this pull request as ready for review February 16, 2025 02:28
@cookie-s cookie-s force-pushed the avm2-perspective-projection branch 2 times, most recently from e929ede to afc763f Compare February 16, 2025 02:51
Comment on lines +17 to +21
// Not associated with any DO
None => 500.0,
// Stage's PerspectiveProjection
Some(dobj) if dobj.as_stage().is_some() => 500.0,
Copy link
Contributor Author

@cookie-s cookie-s Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where this value 500 comes from. It fits the output from the test in FP.

private var displayObject: DisplayObject = null;

[Ruffle(NativeAccessible)]
private var fov: Number = 55.0;
Copy link
Contributor Author

@cookie-s cookie-s Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From TestTransform() result, fieldOfView should be saved and focalLength should be computed from it.
PP(FOV:55, FL:480.25) assignment to Sprite.transform.perspectiveProjection produces PP(FOV:55, FL:288.15) (when SWF width is 300).

@cookie-s cookie-s force-pushed the avm2-perspective-projection branch from afc763f to 2aa2853 Compare February 16, 2025 04:26
@emergence75
Copy link

Copy link
Collaborator

@adrian17 adrian17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it all looks fine, but if you don’t mind, I wanna investigate a bit into the remaining unknowns; but I’ll only be able to do it on wednesday.

stub_method("flash.geom.PerspectiveProjection", "toMatrix3D");
return new Matrix3D();
var fl: Number = this.focalLength;
return new Matrix3D(new <Number>[
Copy link
Collaborator

@adrian17 adrian17 Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be sure, this is a complete matrix impl? Asking due to the removed stub.

Copy link
Contributor Author

@cookie-s cookie-s Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe so. For other methods, especially setters are related to unimplemented rendering/visual, but I believe this toMatrix3D just returns the Matrix3D object.

Ah, but only if the small but not very small floating point number differences are allowed. Please see precision in TestToMatrix3D test function. There is unexplainable numerical errors which is now rounded to approximation in the test.

Except for that, I believe all features in toMatrix3D are implemented.

@adrian17
Copy link
Collaborator

adrian17 commented Feb 16, 2025

As for emergence75’s code, note that we did find issues with some of the changes there (see: #18495 (comment) and the subsequent comment). I know that since then it was replaced by a newer PR (which I’m sorry for not commenting on), but as far as I’m aware, the listed concerns about the changes still apply :( With that, I’d be careful with treating it as a source.

@kjarosh kjarosh added A-avm2 Area: AVM2 (ActionScript 3) T-compat Type: Compatibility with Flash Player labels Feb 16, 2025
@cookie-s
Copy link
Contributor Author

this might be useful, take a look

Oh thank you. My PR might be better to implement the input validation for fieldOfView setter.

I wanna investigate a bit into the remaining unknowns

Sure thank you!

@cookie-s cookie-s force-pushed the avm2-perspective-projection branch from 2aa2853 to 3fadf21 Compare February 18, 2025 13:45
// Stage's PerspectiveProjection
Some(dobj) if dobj.as_stage().is_some() => 500.0,
// root's PerspectiveProjection
Some(dobj) if dobj.is_root() => activation.context.stage.stage_size().0 as f64,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this has the same logic as the one below, any reason for it to be separate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. No! Thank you, merged to the line below at f6f2aba

import flash.geom.Matrix3D;
import flash.geom.Point;

public class PerspectiveProjection {
// Getters are stubbed with what seem to be Flash's default values
[Ruffle(NativeAccessible)]
private var displayObject: DisplayObject = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually need the live reference to the DO? What if instead, only the width value was stored?

Copy link
Contributor Author

@cookie-s cookie-s Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, storing only width passes the current test, but another observation by for example this code:

        private function TestTransformUpdate(): void {
            var s: Sprite = new Sprite();

            trace("// Set non-null to transform.perspectiveProjection");
            s.transform.perspectiveProjection = new PerspectiveProjection();
            printProps(s.transform.perspectiveProjection);

            trace("// Set null to transform.perspectiveProjection");
            s.transform.perspectiveProjection.fieldOfView = 100;
            printProps(s.transform.perspectiveProjection);
        }

shows some setter in DO.transform.perspectiveProjection : PerspectiveProjection should update the values in DO.

It's the similar behavior to transform.matrix3D rather than transform.matrix in terms of what we discussed before: #18810 (comment)
(although that setter behavior is not implemented to matrix3D and transform.perspectiveProjection setter is almost imcomplete as of now.)

Given that, we will anyway need reference to DO at some point I believe.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, yeah.

            var a = dobj.transform.perspectiveProjection;
            var b = dobj.transform.perspectiveProjection;
            trace(a === b); // false
            a.fieldOfView = 123;
            trace(b.fieldOfView); // 123

Copy link
Collaborator

@adrian17 adrian17 Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add some TODO comments explaining the above, and maybe a known-failure test? But just a comment is enough, I think I'm gonna approve the PR in a moment.

although that setter behavior is not implemented to matrix3D and transform.perspectiveProjection setter is almost imcomplete as of now

Sure, I think this is an okay compromise.

@cookie-s cookie-s force-pushed the avm2-perspective-projection branch from 3fadf21 to f5e13c0 Compare February 20, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-avm2 Area: AVM2 (ActionScript 3) T-compat Type: Compatibility with Flash Player
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants