-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Standardize Vectors and Colors #13699
Conversation
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
3 similar comments
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/13699/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/13699/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/13699/merge#BCU1XR#0 |
I love the overall idea, let s move it as a draft until the 6.0 version will be released. What we want to be sure of is:
It would be nice to see perf tests to compare new and old version with measurements on Chrome, FF, Safari and Babylon Native. Those classes are used so often we can not risk any perf hit in their usage. |
I agree with @sebavan and love the idea! Regarding performance, what concerns me is the use of getter/setter everywhere, while we used direct properties in a number of cases... We should make sure this is not a problem and do some measurements with stress tests.
Yes, |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
I believe the test fails have to do with |
It's hard to say, you should try debugging one of the simpler playgrounds that fails (e.g. https://playground.babylonjs.com/#484RHA#0). Spector would probably help you compare the inputs in each case. |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
@Popov72 @sebavan I did some diffing and found the only difference between the reference and PR scenes were two unique IDs. To repoduce:
I'm not sure what is causing the rendering issues. Perhaps someone with more in-depth knowledge of the rendering can take a look? |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
@dr-vortex We are currently very busy with the new version coming out this Thursday, but we will come back to this PR as soon as possible! |
@Popov72 No pressure on getting this PR merged immediately, we have time. |
@dr-vortex before we are coming back to this PR, it would be great to have the perf impact analysis of the PR ? I can not make things slower and it would be great to prove out it has 0 negative impact. |
Sure @sebavan, though I'd like to get it passing the tests before I look at the performance impacts. Just a thought, it may be beneficial to use array access instead of the getters internally (e.g. |
@dr-vortex regarding the tests, there is nothing obvious, you will need to troubleshoot manually :-( Regarding perfs, the checks would need to be done cross plat (V8/Webkit/SpiderMonkey/Hermes...) as they all have different optimizations paths and I really wonder if it will be able to be at least as fast so I do not want you to waste time if we can not reach the same perfs. As a good example https://github.com/BabylonJS/Babylon.js/pull/13742/files where factorizing the code was breaking optims pretty badly for no apparent reasons :-) |
I wanted to try your code locally, but I have a problem with Typescript because For reference, the implementation of public static FromArray<T extends Vector>(this: VectorConstructor<T>, array: DeepImmutable<ArrayLike<number>>, offset: number = 0): T {
const ref = new this();
this.FromArrayToRef(array, offset, ref);
return ref;
} Doing The type cc @sebavan in case he has a solution, as I am far from an expert in Typescript. If there is no solution, |
@Popov72
I think this is the best solution for now. Maybe if static |
This is by design. Static methods belong to an object and are not inherited. They might work, depending on the way the object was generated, but nonetheless - to have proper types they should be created on each one of the objects that need it. I will pull this PR later today or tomorrow and fully review it. It looks great! just need to make sure it doesn't break anything. |
@sebavan Since 6.0 is out I'm going to mark it as read for review (so reviews can be done), though It would probably be best to wait until the lighting issue is fixed before merging.
@RaananW It currently breaks some lighting for unknown reasons (I think it is related to |
Before merging, it is essential to ensure the following:
(note that @sebavan is currently on vacation) |
Note: Made changes to new branch (branched from a recent commit), discarded old commits, and force pushed. |
Note for multiplyToRef, scaleToRef, scaleAndAddToRef, and clampToRef: Return types changed from `this` to the result/ref.
Also modified Vector3.length to use lengthSquared
Fixed some comments Changed Vector4.length to use lengthSquared
Fixed Vector2.normalize tests
Would you all mind running performance tests for the new approach? I am also considering adding a standardized access method (e.g. numbered indexes). It would not be where the data is stored, just an accessory (like how In addition, I would like to mention that this approach changes some return values for |
Everything where you are now calling ...toRef vs doing the same inlined code might be a bit slower in some browser. It was actually not doing it before by design. I do not know if color and vector needs to be that close. (they could but I am wondering if they need to, for instance, what does lenght represent for a color ? |
Thank you for the insight.
I had thought of that. I will fix using
I've changed the colors to implement
Please ignore my earlier comment concerning property access. For tests, |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Fixed Vector2.normalize test Updated minimize/maxmize fromFloats
Change VectorN fromArray to use FromArrayToRef
Currently, we have 5 completely different classes: Vector2, Vector3, Vector4, Color3, and Color4. All 5 define some coordinates ({x, y, z}, {r, g, b}, etc.) and provide some methods for different operations on those coordinates (e.g.
add
,subtract
,multiplyInPlaceFromFloats
).This pull request introduces a new class:
Vector
. AVector
represents any N-dimensional vector, providing the various methods and such in one class. The 5 classes mentioned above extendVector
and add any specific logic, as well as the getters and setters for named coordinates (e.g.x
andy
).In addition to consolidating code,
Vector
ensures that some methods which were previously not available in one of the classes (e.g.minimizeInPlaceFromFloats
) are available across all classes. Furthermore, if bug fixes or enhancements are made, they can be done in one place rather than five.Compatibility / Interoperability
Vector
methods that take a list of values have overloads for 2, 3, and 4 arguments/dimensions, so current classes always have an overload that matches their dimension.