Pārlūkot izejas kodu

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into NPM

sebavan 5 gadi atpakaļ
vecāks
revīzija
41c3a55773

+ 1 - 1
dist/preview release/what's new.md

@@ -128,7 +128,7 @@
 - Added support for (experimental) haptic actuators ([#8068](https://github.com/BabylonJS/Babylon.js/issues/8068)) ([RaananW](https://github.com/RaananW))
 - It is now possible to enable experimental (AR) features using the options of the default xr helper ([RaananW](https://github.com/RaananW))
 - Full support for right handed systems ([#8132](https://github.com/BabylonJS/Babylon.js/issues/8132)) ([RaananW](https://github.com/RaananW))
-- WebXR anchors feature ([#7917](https://github.com/BabylonJS/Babylon.js/issues/7917)) ([RaananW](https://github.com/RaananW))
+- WebXR anchors feature implemented ([#7917](https://github.com/BabylonJS/Babylon.js/issues/7917)) ([RaananW](https://github.com/RaananW))
 
 ### Collisions
 

+ 0 - 142
src/Engines/Native/nativeShaderProcessor.ts

@@ -1,142 +0,0 @@
-import { WebGL2ShaderProcessor } from "../WebGL/webGL2ShaderProcessors";
-import { VertexBuffer } from "../../Meshes/buffer";
-
-// These numbers must match the values for bgfx::Attrib::Enum
-const attributeLocations: { [kind: string]: number } = {
-    [VertexBuffer.PositionKind]: 0,
-    [VertexBuffer.NormalKind]: 1,
-    [VertexBuffer.TangentKind]: 2,
-    [VertexBuffer.UVKind]: 10,
-    [VertexBuffer.UV2Kind]: 11,
-    [VertexBuffer.UV3Kind]: 12,
-    [VertexBuffer.UV4Kind]: 13,
-    [VertexBuffer.ColorKind]: 4,
-    [VertexBuffer.MatricesIndicesKind]: 8,
-    [VertexBuffer.MatricesWeightsKind]: 9,
-};
-// Remap BJS names to bgfx names
-const attributeBGFXName: { [kind: string]: string } = {
-    [VertexBuffer.PositionKind]: "a_position",
-    [VertexBuffer.NormalKind]: "a_normal",
-    [VertexBuffer.TangentKind]: "a_tangent",
-    [VertexBuffer.UVKind]: "a_texcoord0",
-    [VertexBuffer.UV2Kind]: "a_texcoord1",
-    [VertexBuffer.UV3Kind]: "a_texcoord2",
-    [VertexBuffer.UV4Kind]: "a_texcoord3",
-    [VertexBuffer.ColorKind]: "a_color0",
-    [VertexBuffer.MatricesIndicesKind]: "a_indices",
-    [VertexBuffer.MatricesWeightsKind]: "a_weight",
-};
-
-// Must match bgfx::Attrib::TexCoord0
-const firstGenericAttributeLocation = 10;
-
-// Must match bgfx::Attrib::TexCoord7
-const lastGenericAttributeLocation = 17;
-
-/** @hidden */
-export class NativeShaderProcessor extends WebGL2ShaderProcessor {
-    private _genericAttributeLocation: number;
-    private _varyingLocationCount: number;
-    private _varyingLocationMap: { [name: string]: number };
-    private _replacements: Array<{ searchValue: RegExp, replaceValue: string }>;
-    private _textureCount: number;
-    private _uniforms: Array<string>;
-
-    public lineProcessor(line: string): string {
-        for (const replacement of this._replacements) {
-            line = line.replace(replacement.searchValue, replacement.replaceValue);
-        }
-
-        return line;
-    }
-
-    public attributeProcessor(attribute: string): string {
-        const match = attribute.match(/attribute\s+[^\s]+\s+([^\s]+)\s*(?:\[.+\])?\s*;/)!;
-        const name = match[1];
-
-        let location = attributeLocations[name];
-        if (location === undefined) {
-            location = this._genericAttributeLocation++;
-            if (location > lastGenericAttributeLocation) {
-                throw new Error("Exceeded maximum custom attributes");
-            }
-        }
-        let newName = attributeBGFXName[name];
-        if (newName === undefined) {
-            throw new Error("Can't find bgfx name mapping");
-        }
-        attribute = attribute.replace(name, newName);
-        this._replacements.push({ searchValue: new RegExp(`\\b${name}\\b`, 'g'), replaceValue: `${newName}` });
-        return `layout(location=${location}) ${super.attributeProcessor(attribute)}`;
-    }
-
-    public varyingProcessor(varying: string, isFragment: boolean): string {
-        let location: number;
-
-        if (isFragment) {
-            location = this._varyingLocationMap[varying];
-        }
-        else {
-            location = this._varyingLocationCount++;
-            this._varyingLocationMap[varying] = location;
-        }
-
-        return `layout(location=${location}) ${super.varyingProcessor(varying, isFragment)}`;
-    }
-
-    public uniformProcessor(uniform: string): string {
-        const match = uniform.match(/uniform\s+([^\s]+)\s+([^\s]+)\s*(?:\[.+\])?\s*;/)!;
-        const type = match[1];
-        const name = match[2];
-
-        switch (type) {
-            case "sampler2D":
-            case "samplerCube": {
-                const suffix = type.substr(7);
-                const binding = this._textureCount++;
-                this._replacements.push({ searchValue: new RegExp(`\\b${name}\\b`), replaceValue: `sampler${suffix}(${name}Texture, ${name})` });
-                return `layout(binding=${binding}) uniform texture${suffix} ${name}Texture;\nlayout(binding=${binding}) uniform sampler ${name};`;
-            }
-            case "float": {
-                this._replacements.push({ searchValue: new RegExp(`\\b${name}\\b`), replaceValue: `${name}.x` });
-                uniform = `uniform vec4 ${name};`;
-                break;
-            }
-            case "vec2": {
-                this._replacements.push({ searchValue: new RegExp(`\\b${name}\\b`), replaceValue: `${name}.xy` });
-                uniform = `uniform vec4 ${name};`;
-                break;
-            }
-            case "vec3": {
-                this._replacements.push({ searchValue: new RegExp(`\\b${name}\\b`), replaceValue: `${name}.xyz` });
-                uniform = `uniform vec4 ${name};`;
-                break;
-            }
-        }
-
-        this._uniforms.push(uniform);
-        return this._uniforms.length === 1 ? "<UNIFORM>" : "";
-    }
-
-    public preProcessor(code: string, defines: string[], isFragment: boolean): string {
-        this._genericAttributeLocation = firstGenericAttributeLocation;
-
-        if (!isFragment) {
-            this._varyingLocationCount = 0;
-            this._varyingLocationMap = {};
-        }
-
-        this._replacements = [];
-        this._textureCount = 0;
-        this._uniforms = [];
-        return code;
-    }
-
-    public postProcessor(code: string, defines: string[], isFragment: boolean): string {
-        code = super.postProcessor(code, defines, isFragment);
-        code = code.replace("<UNIFORM>", `layout(binding=0) uniform Frame {\n${this._uniforms.join("\n")}\n};`);
-        code = code.replace("out vec4 glFragColor", "layout(location=0) out vec4 glFragColor");
-        return code;
-    }
-}

+ 2 - 2
src/Engines/nativeEngine.ts

@@ -17,13 +17,13 @@ import { IColor4Like } from '../Maths/math.like';
 import { Scene } from "../scene";
 import { RenderTargetCreationOptions } from "../Materials/Textures/renderTargetCreationOptions";
 import { IPipelineContext } from './IPipelineContext';
-import { NativeShaderProcessor } from './Native/nativeShaderProcessor';
 import { Logger } from "../Misc/logger";
 import { Constants } from './constants';
 import { ThinEngine, ISceneLike } from './thinEngine';
 import { IWebRequest } from '../Misc/interfaces/iWebRequest';
 import { EngineStore } from './engineStore';
 import { ShaderCodeInliner } from "./Processors/shaderCodeInliner";
+import { WebGL2ShaderProcessor } from '../Engines/WebGL/webGL2ShaderProcessors';
 
 interface INativeEngine {
     dispose(): void;
@@ -270,7 +270,7 @@ export class NativeEngine extends Engine {
         }
 
         // Shader processor
-        this._shaderProcessor = new NativeShaderProcessor();
+        this._shaderProcessor = new WebGL2ShaderProcessor();
     }
 
     public dispose(): void {

+ 1 - 1
src/Physics/Plugins/ammoJSPlugin.ts

@@ -1031,7 +1031,7 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
     public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
         var trans = impostor.physicsBody.getWorldTransform();
 
-        // If rotation/position has changed update and activate riged body
+        // If rotation/position has changed update and activate rigged body
         if (
             trans.getOrigin().x() != newPosition.x ||
             trans.getOrigin().y() != newPosition.y ||

+ 19 - 17
src/Physics/Plugins/cannonJSPlugin.ts

@@ -43,7 +43,8 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
     }
 
     public setGravity(gravity: Vector3): void {
-        this.world.gravity.copy(gravity);
+        const vec = gravity;
+        this.world.gravity.set(vec.x, vec.y, vec.z);
     }
 
     public setTimeStep(timeStep: number) {
@@ -141,7 +142,8 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
             //Should be tested!
             if (oldBody) {
                 ['force', 'torque', 'velocity', 'angularVelocity'].forEach(function(param) {
-                    impostor.physicsBody[param].copy(oldBody[param]);
+                    const vec = oldBody[param];
+                    impostor.physicsBody[param].set(vec.x, vec.y, vec.z);
                 });
             }
             this._processChildMeshes(impostor);
@@ -206,10 +208,10 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
         var jointData = impostorJoint.joint.jointData;
         //TODO - https://github.com/schteppe/this.BJSCANNON.js/blob/gh-pages/demos/collisionFilter.html
         var constraintData = {
-            pivotA: jointData.mainPivot ? new this.BJSCANNON.Vec3().copy(jointData.mainPivot) : null,
-            pivotB: jointData.connectedPivot ? new this.BJSCANNON.Vec3().copy(jointData.connectedPivot) : null,
-            axisA: jointData.mainAxis ? new this.BJSCANNON.Vec3().copy(jointData.mainAxis) : null,
-            axisB: jointData.connectedAxis ? new this.BJSCANNON.Vec3().copy(jointData.connectedAxis) : null,
+            pivotA: jointData.mainPivot ? new this.BJSCANNON.Vec3().set(jointData.mainPivot.x, jointData.mainPivot.y, jointData.mainPivot.z) : null,
+            pivotB: jointData.connectedPivot ? new this.BJSCANNON.Vec3().set(jointData.connectedPivot.x, jointData.connectedPivot.y, jointData.connectedPivot.z) : null,
+            axisA: jointData.mainAxis ? new this.BJSCANNON.Vec3().set(jointData.mainAxis.x, jointData.mainAxis.y, jointData.mainAxis.z) : null,
+            axisB: jointData.connectedAxis ? new this.BJSCANNON.Vec3().set(jointData.connectedAxis.x, jointData.connectedAxis.y, jointData.connectedAxis.z) : null,
             maxForce: jointData.nativeParams.maxForce,
             collideConnected: !!jointData.collision
         };
@@ -524,25 +526,25 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
             mesh.computeWorldMatrix(true);
         } else if (impostor.type === PhysicsImpostor.MeshImpostor) {
             this._tmpDeltaPosition.copyFromFloats(0, 0, 0);
-            //this._tmpPosition.copyFrom(object.position);
         }
 
         impostor.setDeltaPosition(this._tmpDeltaPosition);
         //Now update the impostor object
-        impostor.physicsBody.position.copy(this._tmpPosition);
-        impostor.physicsBody.quaternion.copy(quaternion);
+        impostor.physicsBody.position.set(this._tmpPosition.x, this._tmpPosition.y, this._tmpPosition.z);
+        impostor.physicsBody.quaternion.set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
     }
 
     public setTransformationFromPhysicsBody(impostor: PhysicsImpostor) {
-        impostor.object.position.copyFrom(impostor.physicsBody.position);
+        impostor.object.position.set(impostor.physicsBody.position.x, impostor.physicsBody.position.y, impostor.physicsBody.position.z);
         if (impostor.object.rotationQuaternion) {
-            impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
+            const q = impostor.object.rotationQuaternion;
+            impostor.object.rotationQuaternion.set(q.x, q.y, q.z, q.w);
         }
     }
 
     public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
-        impostor.physicsBody.position.copy(newPosition);
-        impostor.physicsBody.quaternion.copy(newRotation);
+        impostor.physicsBody.position.set(newPosition.x, newPosition.y, newPosition.z);
+        impostor.physicsBody.quaternion.set(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
     }
 
     public isSupported(): boolean {
@@ -550,11 +552,11 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
     }
 
     public setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
-        impostor.physicsBody.velocity.copy(velocity);
+        impostor.physicsBody.velocity.set(velocity.x, velocity.y, velocity.z);
     }
 
     public setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
-        impostor.physicsBody.angularVelocity.copy(velocity);
+        impostor.physicsBody.angularVelocity.set(velocity.x, velocity.y, velocity.z);
     }
 
     public getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3> {
@@ -688,8 +690,8 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
                         interpvelo.scale(h_div_dt, interpvelo);
                         b.position.vadd(interpvelo, b.interpolatedPosition);
                     } else {
-                        b.interpolatedPosition.copy(b.position);
-                        b.interpolatedQuaternion.copy(b.quaternion);
+                        b.interpolatedPosition.set(b.position.x, b.position.y, b.position.z);
+                        b.interpolatedQuaternion.set(b.quaternion.x, b.quaternion.y, b.quaternion.z, b.quaternion.w);
                     }
                 }
             }

+ 10 - 8
src/Physics/Plugins/oimoJSPlugin.ts

@@ -29,7 +29,7 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
     }
 
     public setGravity(gravity: Vector3) {
-        this.world.gravity.copy(gravity);
+        this.world.gravity.set(gravity.x, gravity.y, gravity.z);
     }
 
     public setTimeStep(timeStep: number) {
@@ -340,14 +340,16 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
                 while (parent.next) {
                     parent = parent.next;
                 }
-                impostor.object.position.copyFrom(parent.position);
+                impostor.object.position.set(parent.position.x, parent.position.y, parent.position.z);
             } else {
-                impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
+                const pos = impostor.physicsBody.getPosition();
+                impostor.object.position.set(pos.x, pos.y, pos.z);
             }
             //}
 
             if (impostor.object.rotationQuaternion) {
-                impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
+                const quat = impostor.physicsBody.getQuaternion();
+                impostor.object.rotationQuaternion.set(quat.x, quat.y, quat.z, quat.w);
             }
         }
     }
@@ -358,8 +360,8 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
         if (impostor.physicsBody.shapes.next) {
             return;
         }
-        body.position.copy(newPosition);
-        body.orientation.copy(newRotation);
+        body.position.set(newPosition.x, newPosition.y, newPosition.z);
+        body.orientation.set(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
         body.syncShapes();
         body.awake();
     }
@@ -373,11 +375,11 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
     }*/
 
     public setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
-        impostor.physicsBody.linearVelocity.copy(velocity);
+        impostor.physicsBody.linearVelocity.set(velocity.x, velocity.y, velocity.z);
     }
 
     public setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
-        impostor.physicsBody.angularVelocity.copy(velocity);
+        impostor.physicsBody.angularVelocity.set(velocity.x, velocity.y, velocity.z);
     }
 
     public getLinearVelocity(impostor: PhysicsImpostor): Nullable<Vector3> {

+ 6 - 4
src/XR/webXRCamera.ts

@@ -126,8 +126,11 @@ export class WebXRCamera extends FreeCamera {
         }
 
         if (pose.transform) {
-            this._referencedPosition.copyFrom(<any>(pose.transform.position));
-            this._referenceQuaternion.copyFrom(<any>(pose.transform.orientation));
+            const pos = pose.transform.position;
+            this._referencedPosition.set(pos.x, pos.y, pos.z);
+            const orientation = pose.transform.orientation;
+
+            this._referenceQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);
             if (!this._scene.useRightHandedSystem) {
                 this._referencedPosition.z *= -1;
                 this._referenceQuaternion.z *= -1;
@@ -285,8 +288,7 @@ export class WebXRCamera extends FreeCamera {
         const pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(referenceSpace);
 
         if (pose) {
-            const pos = new Vector3();
-            pos.copyFrom(<any>(pose.transform.position));
+            const pos = new Vector3(pose.transform.position.x, pose.transform.position.y, pose.transform.position.z);
             if (!this._scene.useRightHandedSystem) {
                 pos.z *= -1;
             }

+ 8 - 4
src/XR/webXRInputSource.ts

@@ -173,8 +173,10 @@ export class WebXRInputSource {
 
         // Update the pointer mesh
         if (pose) {
-            this.pointer.position.copyFrom(<any>(pose.transform.position));
-            this.pointer.rotationQuaternion!.copyFrom(<any>(pose.transform.orientation));
+            const pos = pose.transform.position;
+            this.pointer.position.set(pos.x, pos.y, pos.z);
+            const orientation = pose.transform.orientation;
+            this.pointer.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);
             if (!this._scene.useRightHandedSystem) {
                 this.pointer.position.z *= -1;
                 this.pointer.rotationQuaternion!.z *= -1;
@@ -186,8 +188,10 @@ export class WebXRInputSource {
         if (this.inputSource.gripSpace && this.grip) {
             let pose = xrFrame.getPose(this.inputSource.gripSpace, referenceSpace);
             if (pose) {
-                this.grip.position.copyFrom(<any>(pose.transform.position));
-                this.grip.rotationQuaternion!.copyFrom(<any>(pose.transform.orientation));
+                const pos = pose.transform.position;
+                const orientation = pose.transform.orientation;
+                this.grip.position.set(pos.x, pos.y, pos.z);
+                this.grip.rotationQuaternion!.set(orientation.x, orientation.y, orientation.z, orientation.w);
                 if (!this._scene.useRightHandedSystem) {
                     this.grip.position.z *= -1;
                     this.grip.rotationQuaternion!.z *= -1;