@onerjs/core 8.27.14 → 8.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Behaviors/Meshes/handConstraintBehavior.js.map +1 -1
- package/Buffers/bufferUtils.d.ts +1 -2
- package/Buffers/bufferUtils.js +3 -4
- package/Buffers/bufferUtils.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Materials/Textures/texture.js +9 -2
- package/Materials/Textures/texture.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.js +1 -1
- package/Meshes/Compression/dracoEncoder.js.map +1 -1
- package/Meshes/geometry.js +1 -1
- package/Meshes/geometry.js.map +1 -1
- package/Particles/gpuParticleSystem.js +2 -1
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/thinParticleSystem.js +4 -3
- package/Particles/thinParticleSystem.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +5 -0
- package/Physics/v2/physicsAggregate.js +26 -0
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +6 -1
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Shaders/geometry.fragment.js +3 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/geometry.vertex.js +10 -2
- package/Shaders/geometry.vertex.js.map +1 -1
- package/ShadersWGSL/geometry.fragment.js +3 -1
- package/ShadersWGSL/geometry.fragment.js.map +1 -1
- package/ShadersWGSL/geometry.vertex.js +10 -2
- package/ShadersWGSL/geometry.vertex.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.d.ts +1 -1
- package/XR/features/WebXRBackgroundRemover.d.ts +1 -1
- package/XR/features/WebXRControllerMovement.d.ts +1 -1
- package/XR/features/WebXRControllerPhysics.d.ts +1 -1
- package/XR/features/WebXRControllerPointerSelection.d.ts +1 -1
- package/XR/features/WebXRControllerTeleportation.d.ts +1 -1
- package/XR/features/WebXRDOMOverlay.d.ts +1 -1
- package/XR/features/WebXRDepthSensing.d.ts +1 -1
- package/XR/features/WebXREyeTracking.d.ts +1 -1
- package/XR/features/WebXRFeaturePointSystem.d.ts +1 -1
- package/XR/features/WebXRHandTracking.d.ts +1 -1
- package/XR/features/WebXRHitTest.d.ts +1 -1
- package/XR/features/WebXRHitTestLegacy.d.ts +1 -1
- package/XR/features/WebXRImageTracking.d.ts +1 -1
- package/XR/features/WebXRLayers.d.ts +1 -1
- package/XR/features/WebXRLightEstimation.d.ts +1 -1
- package/XR/features/WebXRMeshDetector.d.ts +1 -1
- package/XR/features/WebXRNearInteraction.d.ts +1 -1
- package/XR/features/WebXRPlaneDetector.d.ts +1 -1
- package/XR/features/WebXRRawCameraAccess.d.ts +1 -1
- package/XR/features/WebXRSpaceWarp.d.ts +1 -1
- package/XR/webXRDefaultExperience.js +1 -1
- package/XR/webXRDefaultExperience.js.map +1 -1
- package/XR/webXRFeaturesManager.d.ts +116 -27
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/package.json +1 -1
|
@@ -103,6 +103,11 @@ export declare class PhysicsAggregate {
|
|
|
103
103
|
private _getObjectBoundingBox;
|
|
104
104
|
private _hasVertices;
|
|
105
105
|
private _addSizeOptions;
|
|
106
|
+
/**
|
|
107
|
+
* Updates the options for the physics aggregate with the provided parameters.
|
|
108
|
+
* @param _options - The new set of options to update the physics aggregate with.
|
|
109
|
+
*/
|
|
110
|
+
updateOptions(_options: PhysicsAggregateParameters): void;
|
|
106
111
|
/**
|
|
107
112
|
* Releases the body, shape and material
|
|
108
113
|
*/
|
|
@@ -141,6 +141,32 @@ export class PhysicsAggregate {
|
|
|
141
141
|
break;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Updates the options for the physics aggregate with the provided parameters.
|
|
146
|
+
* @param _options - The new set of options to update the physics aggregate with.
|
|
147
|
+
*/
|
|
148
|
+
updateOptions(_options) {
|
|
149
|
+
this._options.mass = _options.mass === void 0 ? 0 : _options.mass;
|
|
150
|
+
this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;
|
|
151
|
+
this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;
|
|
152
|
+
const motionType = this._options.mass === 0 ? 0 /* PhysicsMotionType.STATIC */ : 2 /* PhysicsMotionType.DYNAMIC */;
|
|
153
|
+
const startAsleep = this._options.startAsleep ?? false;
|
|
154
|
+
if (motionType !== this.body.motionType) {
|
|
155
|
+
this.body.setMotionType(motionType);
|
|
156
|
+
}
|
|
157
|
+
if (startAsleep !== this.body.startAsleep) {
|
|
158
|
+
this.body.startAsleep = startAsleep;
|
|
159
|
+
}
|
|
160
|
+
this._addSizeOptions();
|
|
161
|
+
if (this._options.isTriggerShape) {
|
|
162
|
+
this.shape.isTrigger = true;
|
|
163
|
+
}
|
|
164
|
+
if (this.material) {
|
|
165
|
+
this.material.friction = this._options.friction;
|
|
166
|
+
this.material.restitution = this._options.restitution;
|
|
167
|
+
}
|
|
168
|
+
this.body.setMassProperties({ mass: this._options.mass });
|
|
169
|
+
}
|
|
144
170
|
/**
|
|
145
171
|
* Releases the body, shape and material
|
|
146
172
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAOlE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAmExD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAoBzB;IACI;;OAEG;IAC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C,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;oBAC/D,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,aAAqB,CAAC;gBACpD,CAAC;qBAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACvE,MAAM,IAAI,KAAK,CACX,oJAAoJ,CACvJ,CAAC;gBACN,CAAC;gBACD,MAAM;YACV;gBACI,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;gBAC9F,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;gBACzE,MAAM;QACd,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAC9E,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Quaternion, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { WithinEpsilon } from \"../../Maths/math.scalar.functions\";\r\nimport { PhysicsMotionType, PhysicsShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * Orientation for box\r\n */\r\n rotation?: Quaternion;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n startAsleep?: boolean;\r\n\r\n /**\r\n * If true, mark the created shape as a trigger shape\r\n */\r\n isTriggerShape?: boolean;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instantiates all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient than handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _disposeShapeWhenDisposed = true;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: PhysicsShapeType | PhysicsShape,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n const m = transformNode as Mesh;\r\n if (this.transformNode.parent && this._options.mass !== 0 && m.hasThinInstances) {\r\n Logger.Warn(\r\n \"A physics body has been created for an object which has a parent and thin instances. Babylon physics currently works in local space so unexpected issues may occur.\"\r\n );\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);\r\n this._addSizeOptions();\r\n if ((type as any).getClassName && (type as any).getClassName() === \"PhysicsShape\") {\r\n this.shape = type as PhysicsShape;\r\n this._disposeShapeWhenDisposed = false;\r\n } else {\r\n this.shape = new PhysicsShape({ type: type as PhysicsShapeType, parameters: this._options as any }, this._scene);\r\n }\r\n\r\n if (this._options.isTriggerShape) {\r\n this.shape.isTrigger = true;\r\n }\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n private _getObjectBoundingBox() {\r\n if ((this.transformNode as AbstractMesh).getRawBoundingInfo) {\r\n return (this.transformNode as AbstractMesh).getRawBoundingInfo().boundingBox;\r\n } else {\r\n return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));\r\n }\r\n }\r\n\r\n private _hasVertices(node: TransformNode): boolean {\r\n return (node as any)?.getTotalVertices() > 0;\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n this.transformNode.computeWorldMatrix(true);\r\n const bb = this._getObjectBoundingBox();\r\n const extents = TmpVectors.Vector3[0];\r\n extents.copyFrom(bb.extendSize);\r\n extents.scaleInPlace(2);\r\n extents.multiplyInPlace(this.transformNode.absoluteScaling);\r\n // In case we had any negative scaling, we need to take the absolute value of the extents.\r\n extents.x = Math.abs(extents.x);\r\n extents.y = Math.abs(extents.y);\r\n extents.z = Math.abs(extents.z);\r\n\r\n const min = TmpVectors.Vector3[1];\r\n min.copyFrom(bb.minimum);\r\n min.multiplyInPlace(this.transformNode.absoluteScaling);\r\n\r\n if (!this._options.center) {\r\n const center = new Vector3();\r\n center.copyFrom(bb.center);\r\n center.multiplyInPlace(this.transformNode.absoluteScaling);\r\n this._options.center = center;\r\n }\r\n\r\n switch (this.type) {\r\n case PhysicsShapeType.SPHERE:\r\n if (!this._options.radius && WithinEpsilon(extents.x, extents.y, 0.0001) && WithinEpsilon(extents.x, extents.z, 0.0001)) {\r\n this._options.radius = extents.x / 2;\r\n } else if (!this._options.radius) {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.\");\r\n this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;\r\n }\r\n break;\r\n case PhysicsShapeType.CAPSULE:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y - capRadius, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.CYLINDER:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.MESH:\r\n case PhysicsShapeType.CONVEX_HULL:\r\n case PhysicsShapeType.HEIGHTFIELD:\r\n if (!this._options.mesh && this._hasVertices(this.transformNode)) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else if (!this._options.mesh || !this._hasVertices(this._options.mesh)) {\r\n throw new Error(\r\n \"No valid mesh was provided for mesh or convex hull shape parameter. Please provide a mesh with valid geometry (number of vertices greater than 0).\"\r\n );\r\n }\r\n break;\r\n case PhysicsShapeType.BOX:\r\n this._options.extents = this._options.extents ?? new Vector3(extents.x, extents.y, extents.z);\r\n this._options.rotation = this._options.rotation ?? Quaternion.Identity();\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n if (this._disposeShapeWhenDisposed) {\r\n this.shape.dispose();\r\n }\r\n }\r\n}\r\n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AW,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAC9E,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Quaternion, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { WithinEpsilon } from \"../../Maths/math.scalar.functions\";\r\nimport { PhysicsMotionType, PhysicsShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * Orientation for box\r\n */\r\n rotation?: Quaternion;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n startAsleep?: boolean;\r\n\r\n /**\r\n * If true, mark the created shape as a trigger shape\r\n */\r\n isTriggerShape?: boolean;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instantiates all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient than handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _disposeShapeWhenDisposed = true;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: PhysicsShapeType | PhysicsShape,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n const m = transformNode as Mesh;\r\n if (this.transformNode.parent && this._options.mass !== 0 && m.hasThinInstances) {\r\n Logger.Warn(\r\n \"A physics body has been created for an object which has a parent and thin instances. Babylon physics currently works in local space so unexpected issues may occur.\"\r\n );\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);\r\n this._addSizeOptions();\r\n if ((type as any).getClassName && (type as any).getClassName() === \"PhysicsShape\") {\r\n this.shape = type as PhysicsShape;\r\n this._disposeShapeWhenDisposed = false;\r\n } else {\r\n this.shape = new PhysicsShape({ type: type as PhysicsShapeType, parameters: this._options as any }, this._scene);\r\n }\r\n\r\n if (this._options.isTriggerShape) {\r\n this.shape.isTrigger = true;\r\n }\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n private _getObjectBoundingBox() {\r\n if ((this.transformNode as AbstractMesh).getRawBoundingInfo) {\r\n return (this.transformNode as AbstractMesh).getRawBoundingInfo().boundingBox;\r\n } else {\r\n return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));\r\n }\r\n }\r\n\r\n private _hasVertices(node: TransformNode): boolean {\r\n return (node as any)?.getTotalVertices() > 0;\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n this.transformNode.computeWorldMatrix(true);\r\n const bb = this._getObjectBoundingBox();\r\n const extents = TmpVectors.Vector3[0];\r\n extents.copyFrom(bb.extendSize);\r\n extents.scaleInPlace(2);\r\n extents.multiplyInPlace(this.transformNode.absoluteScaling);\r\n // In case we had any negative scaling, we need to take the absolute value of the extents.\r\n extents.x = Math.abs(extents.x);\r\n extents.y = Math.abs(extents.y);\r\n extents.z = Math.abs(extents.z);\r\n\r\n const min = TmpVectors.Vector3[1];\r\n min.copyFrom(bb.minimum);\r\n min.multiplyInPlace(this.transformNode.absoluteScaling);\r\n\r\n if (!this._options.center) {\r\n const center = new Vector3();\r\n center.copyFrom(bb.center);\r\n center.multiplyInPlace(this.transformNode.absoluteScaling);\r\n this._options.center = center;\r\n }\r\n\r\n switch (this.type) {\r\n case PhysicsShapeType.SPHERE:\r\n if (!this._options.radius && WithinEpsilon(extents.x, extents.y, 0.0001) && WithinEpsilon(extents.x, extents.z, 0.0001)) {\r\n this._options.radius = extents.x / 2;\r\n } else if (!this._options.radius) {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.\");\r\n this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;\r\n }\r\n break;\r\n case PhysicsShapeType.CAPSULE:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y - capRadius, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.CYLINDER:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.MESH:\r\n case PhysicsShapeType.CONVEX_HULL:\r\n case PhysicsShapeType.HEIGHTFIELD:\r\n if (!this._options.mesh && this._hasVertices(this.transformNode)) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else if (!this._options.mesh || !this._hasVertices(this._options.mesh)) {\r\n throw new Error(\r\n \"No valid mesh was provided for mesh or convex hull shape parameter. Please provide a mesh with valid geometry (number of vertices greater than 0).\"\r\n );\r\n }\r\n break;\r\n case PhysicsShapeType.BOX:\r\n this._options.extents = this._options.extents ?? new Vector3(extents.x, extents.y, extents.z);\r\n this._options.rotation = this._options.rotation ?? Quaternion.Identity();\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Updates the options for the physics aggregate with the provided parameters.\r\n * @param _options - The new set of options to update the physics aggregate with.\r\n */\r\n public updateOptions(_options: PhysicsAggregateParameters) {\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n if (motionType !== this.body.motionType) {\r\n this.body.setMotionType(motionType);\r\n }\r\n if (startAsleep !== this.body.startAsleep) {\r\n this.body.startAsleep = startAsleep;\r\n }\r\n this._addSizeOptions();\r\n if (this._options.isTriggerShape) {\r\n this.shape.isTrigger = true;\r\n }\r\n if (this.material) {\r\n this.material.friction = this._options.friction;\r\n this.material.restitution = this._options.restitution;\r\n }\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n if (this._disposeShapeWhenDisposed) {\r\n this.shape.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -414,8 +414,13 @@ export class GeometryBufferRenderer {
|
|
|
414
414
|
return false;
|
|
415
415
|
}
|
|
416
416
|
const defines = [];
|
|
417
|
-
const attribs = [VertexBuffer.PositionKind
|
|
417
|
+
const attribs = [VertexBuffer.PositionKind];
|
|
418
418
|
const mesh = subMesh.getMesh();
|
|
419
|
+
const hasNormals = mesh.isVerticesDataPresent(VertexBuffer.NormalKind);
|
|
420
|
+
if (hasNormals) {
|
|
421
|
+
defines.push("#define HAS_NORMAL_ATTRIBUTE");
|
|
422
|
+
attribs.push(VertexBuffer.NormalKind);
|
|
423
|
+
}
|
|
419
424
|
let uv1 = false;
|
|
420
425
|
let uv2 = false;
|
|
421
426
|
const color = false;
|