@babylonjs/core 6.32.0 → 6.33.0
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/Animations/animatable.js +13 -1
- package/Animations/animatable.js.map +1 -1
- package/Animations/animation.d.ts +4 -0
- package/Animations/animation.js +13 -1
- package/Animations/animation.js.map +1 -1
- package/Animations/runtimeAnimation.js +11 -1
- package/Animations/runtimeAnimation.js.map +1 -1
- package/Behaviors/Meshes/pointerDragBehavior.js +18 -7
- package/Behaviors/Meshes/pointerDragBehavior.js.map +1 -1
- package/Engines/Extensions/engine.dynamicTexture.js +6 -0
- package/Engines/Extensions/engine.dynamicTexture.js.map +1 -1
- package/Engines/Extensions/engine.multiRender.js +1 -1
- package/Engines/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/Extensions/engine.renderTarget.js +1 -1
- package/Engines/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/ICanvas.d.ts +45 -0
- package/Engines/ICanvas.js.map +1 -1
- package/Engines/thinEngine.d.ts +0 -4
- package/Engines/thinEngine.js +2 -24
- package/Engines/thinEngine.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.d.ts +3 -0
- package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.js +11 -4
- package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.js.map +1 -1
- package/FlowGraph/flowGraph.d.ts +1 -0
- package/FlowGraph/flowGraph.js +26 -1
- package/FlowGraph/flowGraph.js.map +1 -1
- package/FlowGraph/utils.d.ts +9 -0
- package/FlowGraph/utils.js +11 -0
- package/FlowGraph/utils.js.map +1 -0
- package/Gizmos/axisDragGizmo.js +1 -1
- package/Gizmos/axisDragGizmo.js.map +1 -1
- package/Gizmos/axisScaleGizmo.d.ts +13 -1
- package/Gizmos/axisScaleGizmo.js +37 -8
- package/Gizmos/axisScaleGizmo.js.map +1 -1
- package/Gizmos/gizmo.d.ts +17 -1
- package/Gizmos/gizmo.js +28 -2
- package/Gizmos/gizmo.js.map +1 -1
- package/Gizmos/planeDragGizmo.d.ts +3 -1
- package/Gizmos/planeDragGizmo.js +5 -3
- package/Gizmos/planeDragGizmo.js.map +1 -1
- package/Gizmos/positionGizmo.d.ts +7 -0
- package/Gizmos/positionGizmo.js +15 -0
- package/Gizmos/positionGizmo.js.map +1 -1
- package/Gizmos/rotationGizmo.d.ts +7 -0
- package/Gizmos/rotationGizmo.js +15 -0
- package/Gizmos/rotationGizmo.js.map +1 -1
- package/Gizmos/scaleGizmo.d.ts +15 -0
- package/Gizmos/scaleGizmo.js +30 -0
- package/Gizmos/scaleGizmo.js.map +1 -1
- package/Materials/Background/backgroundMaterial.js +6 -1
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +3 -3
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.d.ts +4 -0
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +14 -1
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/vertexOutputBlock.js +5 -2
- package/Materials/Node/Blocks/Vertex/vertexOutputBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.js +1 -0
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterialBuildStateSharedData.d.ts +5 -1
- package/Materials/Node/nodeMaterialBuildStateSharedData.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +0 -12
- package/Materials/PBR/pbrBaseMaterial.js +1 -20
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/PBR/pbrSubSurfaceConfiguration.d.ts +10 -0
- package/Materials/PBR/pbrSubSurfaceConfiguration.js +21 -0
- package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.d.ts +5 -0
- package/Materials/Textures/Procedurals/proceduralTexture.js +16 -0
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/Textures/internalTexture.d.ts +4 -0
- package/Materials/Textures/internalTexture.js +8 -1
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/material.d.ts +8 -0
- package/Materials/material.js +19 -0
- package/Materials/material.js.map +1 -1
- package/Materials/shaderMaterial.js +23 -11
- package/Materials/shaderMaterial.js.map +1 -1
- package/Materials/standardMaterial.d.ts +0 -8
- package/Materials/standardMaterial.js +0 -15
- package/Materials/standardMaterial.js.map +1 -1
- package/Maths/math.plane.d.ts +8 -1
- package/Maths/math.plane.js +14 -5
- package/Maths/math.plane.js.map +1 -1
- package/Maths/math.vector.d.ts +2 -1
- package/Maths/math.vector.js +5 -4
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setColorsBlock.js +3 -0
- package/Meshes/Node/Blocks/Set/setColorsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setNormalsBlock.js +3 -0
- package/Meshes/Node/Blocks/Set/setNormalsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setPositionsBlock.js +3 -0
- package/Meshes/Node/Blocks/Set/setPositionsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setTangentsBlock.js +3 -0
- package/Meshes/Node/Blocks/Set/setTangentsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setUVsBlock.js +3 -0
- package/Meshes/Node/Blocks/Set/setUVsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/mergeGeometryBlock.js +6 -0
- package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
- package/Meshes/Node/Blocks/randomBlock.js +1 -1
- package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
- package/Meshes/mesh.vertexData.js +78 -94
- package/Meshes/mesh.vertexData.js.map +1 -1
- package/Meshes/transformNode.d.ts +4 -0
- package/Meshes/transformNode.js +6 -0
- package/Meshes/transformNode.js.map +1 -1
- package/PostProcesses/postProcess.d.ts +88 -3
- package/PostProcesses/postProcess.js +34 -21
- package/PostProcesses/postProcess.js.map +1 -1
- package/Rendering/GaussianSplatting/gaussianSplatting.d.ts +65 -0
- package/Rendering/GaussianSplatting/gaussianSplatting.js +285 -0
- package/Rendering/GaussianSplatting/gaussianSplatting.js.map +1 -0
- package/Rendering/GaussianSplatting/index.d.ts +1 -0
- package/Rendering/GaussianSplatting/index.js +2 -0
- package/Rendering/GaussianSplatting/index.js.map +1 -0
- package/Rendering/index.d.ts +1 -0
- package/Rendering/index.js +1 -0
- package/Rendering/index.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js +119 -44
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js +3 -0
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js.map +1 -1
- package/Shaders/background.fragment.d.ts +2 -0
- package/Shaders/background.fragment.js +7 -0
- package/Shaders/background.fragment.js.map +1 -1
- package/Shaders/background.vertex.d.ts +2 -0
- package/Shaders/background.vertex.js +4 -0
- package/Shaders/background.vertex.js.map +1 -1
- package/Shaders/line.fragment.d.ts +2 -0
- package/Shaders/line.fragment.js +7 -0
- package/Shaders/line.fragment.js.map +1 -1
- package/Shaders/line.vertex.d.ts +2 -0
- package/Shaders/line.vertex.js +4 -0
- package/Shaders/line.vertex.js.map +1 -1
- package/Shaders/pbr.fragment.js +3 -0
- package/Shaders/pbr.fragment.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AbstractMesh } from "../../../Meshes/abstractMesh";
|
|
1
2
|
import { FlowGraphEventBlock } from "../../flowGraphEventBlock";
|
|
2
3
|
import type { FlowGraphContext } from "../../flowGraphContext";
|
|
3
4
|
import type { IFlowGraphBlockConfiguration } from "../../flowGraphBlock";
|
|
@@ -15,6 +16,7 @@ export interface IFlowGraphMeshPickEventBlockConfiguration extends IFlowGraphBlo
|
|
|
15
16
|
export declare class FlowGraphMeshPickEventBlock extends FlowGraphEventBlock {
|
|
16
17
|
config: IFlowGraphMeshPickEventBlockConfiguration;
|
|
17
18
|
constructor(config: IFlowGraphMeshPickEventBlockConfiguration);
|
|
19
|
+
_getReferencedMesh(context: FlowGraphContext): AbstractMesh | undefined;
|
|
18
20
|
/**
|
|
19
21
|
* @internal
|
|
20
22
|
*/
|
|
@@ -26,4 +28,5 @@ export declare class FlowGraphMeshPickEventBlock extends FlowGraphEventBlock {
|
|
|
26
28
|
_cancelPendingTasks(context: FlowGraphContext): void;
|
|
27
29
|
getClassName(): string;
|
|
28
30
|
serialize(serializationObject?: any): void;
|
|
31
|
+
static ClassName: string;
|
|
29
32
|
}
|
|
@@ -3,6 +3,7 @@ import { FlowGraphEventBlock } from "../../flowGraphEventBlock.js";
|
|
|
3
3
|
import { PointerEventTypes } from "../../../Events/pointerEvents.js";
|
|
4
4
|
import { RegisterClass } from "../../../Misc/typeStore.js";
|
|
5
5
|
import { Tools } from "../../../Misc/tools.js";
|
|
6
|
+
import { _isADescendantOf } from "../../utils.js";
|
|
6
7
|
/**
|
|
7
8
|
* @experimental
|
|
8
9
|
* A block that activates when a mesh is picked.
|
|
@@ -15,6 +16,9 @@ export class FlowGraphMeshPickEventBlock extends FlowGraphEventBlock {
|
|
|
15
16
|
super(config);
|
|
16
17
|
this.config = config;
|
|
17
18
|
}
|
|
19
|
+
_getReferencedMesh(context) {
|
|
20
|
+
return this.config.path.getProperty(context);
|
|
21
|
+
}
|
|
18
22
|
/**
|
|
19
23
|
* @internal
|
|
20
24
|
*/
|
|
@@ -27,8 +31,10 @@ export class FlowGraphMeshPickEventBlock extends FlowGraphEventBlock {
|
|
|
27
31
|
}
|
|
28
32
|
context._setExecutionVariable(this, "mesh", mesh);
|
|
29
33
|
pickObserver = mesh.getScene().onPointerObservable.add((pointerInfo) => {
|
|
30
|
-
var _a;
|
|
31
|
-
if (pointerInfo.type === PointerEventTypes.POINTERPICK &&
|
|
34
|
+
var _a, _b, _c;
|
|
35
|
+
if (pointerInfo.type === PointerEventTypes.POINTERPICK &&
|
|
36
|
+
((_a = pointerInfo.pickInfo) === null || _a === void 0 ? void 0 : _a.pickedMesh) &&
|
|
37
|
+
(((_b = pointerInfo.pickInfo) === null || _b === void 0 ? void 0 : _b.pickedMesh) === mesh || _isADescendantOf((_c = pointerInfo.pickInfo) === null || _c === void 0 ? void 0 : _c.pickedMesh, mesh))) {
|
|
32
38
|
this._execute(context);
|
|
33
39
|
}
|
|
34
40
|
});
|
|
@@ -55,12 +61,13 @@ export class FlowGraphMeshPickEventBlock extends FlowGraphEventBlock {
|
|
|
55
61
|
context._deleteExecutionVariable(this, "meshDisposeObserver");
|
|
56
62
|
}
|
|
57
63
|
getClassName() {
|
|
58
|
-
return
|
|
64
|
+
return FlowGraphMeshPickEventBlock.ClassName;
|
|
59
65
|
}
|
|
60
66
|
serialize(serializationObject) {
|
|
61
67
|
super.serialize(serializationObject);
|
|
62
68
|
serializationObject.config.path = this.config.path.serialize();
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
|
-
|
|
71
|
+
FlowGraphMeshPickEventBlock.ClassName = "FGMeshPickEventBlock";
|
|
72
|
+
RegisterClass(FlowGraphMeshPickEventBlock.ClassName, FlowGraphMeshPickEventBlock);
|
|
66
73
|
//# sourceMappingURL=flowGraphMeshPickEventBlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowGraphMeshPickEventBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGlE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD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B,CAAC,CAAC;QAEnF,IAAI,CAAC,QAAQ,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACzD,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAEjD,OAAO,CAAC,wBAAwB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO,CAAC,wBAAwB,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;QAC3D,OAAO,CAAC,wBAAwB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAClE,CAAC;IAEM,YAAY;QACf,OAAO,2BAA2B,CAAC,SAAS,CAAC;IACjD,CAAC;IAEM,SAAS,CAAC,mBAAyB;QACtC,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACrC,mBAAmB,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;IACnE,CAAC;;AAEM,qCAAS,GAAG,sBAAsB,CAAC;AAE9C,aAAa,CAAC,2BAA2B,CAAC,SAAS,EAAE,2BAA2B,CAAC,CAAC","sourcesContent":["import { AbstractMesh } from \"../../../Meshes/abstractMesh\";\r\nimport { FlowGraphEventBlock } from \"../../flowGraphEventBlock\";\r\nimport { PointerEventTypes } from \"../../../Events/pointerEvents\";\r\nimport type { FlowGraphContext } from \"../../flowGraphContext\";\r\nimport type { IFlowGraphBlockConfiguration } from \"../../flowGraphBlock\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport type { FlowGraphPath } from \"../../flowGraphPath\";\r\nimport { Tools } from \"../../../Misc/tools\";\r\nimport { _isADescendantOf } from \"../../utils\";\r\n/**\r\n * @experimental\r\n */\r\nexport interface IFlowGraphMeshPickEventBlockConfiguration extends IFlowGraphBlockConfiguration {\r\n path: FlowGraphPath;\r\n}\r\n/**\r\n * @experimental\r\n * A block that activates when a mesh is picked.\r\n */\r\nexport class FlowGraphMeshPickEventBlock extends FlowGraphEventBlock {\r\n public constructor(public config: IFlowGraphMeshPickEventBlockConfiguration) {\r\n if (config.path.hasTemplateStrings) {\r\n Tools.Warn(\"Template strings are not supported in the path of mesh pick event blocks.\");\r\n }\r\n super(config);\r\n }\r\n\r\n public _getReferencedMesh(context: FlowGraphContext): AbstractMesh | undefined {\r\n return this.config.path.getProperty(context);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _preparePendingTasks(context: FlowGraphContext): void {\r\n let pickObserver = context._getExecutionVariable(this, \"meshPickObserver\");\r\n if (!pickObserver) {\r\n const mesh = this.config.path.getProperty(context);\r\n if (!mesh || !(mesh instanceof AbstractMesh)) {\r\n throw new Error(\"Mesh pick event block requires a valid mesh\");\r\n }\r\n context._setExecutionVariable(this, \"mesh\", mesh);\r\n pickObserver = mesh.getScene().onPointerObservable.add((pointerInfo) => {\r\n if (\r\n pointerInfo.type === PointerEventTypes.POINTERPICK &&\r\n pointerInfo.pickInfo?.pickedMesh &&\r\n (pointerInfo.pickInfo?.pickedMesh === mesh || _isADescendantOf(pointerInfo.pickInfo?.pickedMesh, mesh))\r\n ) {\r\n this._execute(context);\r\n }\r\n });\r\n const disposeObserver = mesh.onDisposeObservable.add(() => this._onDispose);\r\n context._setExecutionVariable(this, \"meshPickObserver\", pickObserver);\r\n context._setExecutionVariable(this, \"meshDisposeObserver\", disposeObserver);\r\n }\r\n }\r\n\r\n public _onDispose(context: FlowGraphContext) {\r\n this._cancelPendingTasks(context);\r\n context._removePendingBlock(this);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _cancelPendingTasks(context: FlowGraphContext): void {\r\n const mesh = context._getExecutionVariable(this, \"mesh\");\r\n const pickObserver = context._getExecutionVariable(this, \"meshPickObserver\");\r\n const disposeObserver = context._getExecutionVariable(this, \"meshDisposeObserver\");\r\n\r\n mesh.getScene().onPointerObservable.remove(pickObserver);\r\n mesh.onDisposeObservable.remove(disposeObserver);\r\n\r\n context._deleteExecutionVariable(this, \"mesh\");\r\n context._deleteExecutionVariable(this, \"meshPickObserver\");\r\n context._deleteExecutionVariable(this, \"meshDisposeObserver\");\r\n }\r\n\r\n public getClassName(): string {\r\n return FlowGraphMeshPickEventBlock.ClassName;\r\n }\r\n\r\n public serialize(serializationObject?: any): void {\r\n super.serialize(serializationObject);\r\n serializationObject.config.path = this.config.path.serialize();\r\n }\r\n\r\n static ClassName = \"FGMeshPickEventBlock\";\r\n}\r\nRegisterClass(FlowGraphMeshPickEventBlock.ClassName, FlowGraphMeshPickEventBlock);\r\n"]}
|
package/FlowGraph/flowGraph.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export declare class FlowGraph {
|
|
|
70
70
|
* Starts the flow graph. Initializes the event blocks and starts listening to events.
|
|
71
71
|
*/
|
|
72
72
|
start(): void;
|
|
73
|
+
private _getContextualOrder;
|
|
73
74
|
/**
|
|
74
75
|
* Disposes of the flow graph. Cancels any pending tasks and removes all event listeners.
|
|
75
76
|
*/
|
package/FlowGraph/flowGraph.js
CHANGED
|
@@ -2,6 +2,8 @@ import { FlowGraphEventBlock } from "./flowGraphEventBlock.js";
|
|
|
2
2
|
import { FlowGraphContext } from "./flowGraphContext.js";
|
|
3
3
|
import { FlowGraphBlock } from "./flowGraphBlock.js";
|
|
4
4
|
import { FlowGraphExecutionBlock } from "./flowGraphExecutionBlock.js";
|
|
5
|
+
import { FlowGraphMeshPickEventBlock } from "./Blocks/Event/flowGraphMeshPickEventBlock.js";
|
|
6
|
+
import { _isADescendantOf } from "./utils.js";
|
|
5
7
|
export var FlowGraphState;
|
|
6
8
|
(function (FlowGraphState) {
|
|
7
9
|
/**
|
|
@@ -66,11 +68,34 @@ export class FlowGraph {
|
|
|
66
68
|
this.createContext();
|
|
67
69
|
}
|
|
68
70
|
for (const context of this._executionContexts) {
|
|
69
|
-
|
|
71
|
+
const contextualOrder = this._getContextualOrder(context);
|
|
72
|
+
for (const block of contextualOrder) {
|
|
70
73
|
block._startPendingTasks(context);
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
77
|
+
_getContextualOrder(context) {
|
|
78
|
+
const order = [];
|
|
79
|
+
for (const block1 of this._eventBlocks) {
|
|
80
|
+
// If the block is a mesh pick, guarantee that picks of children meshes come before picks of parent meshes
|
|
81
|
+
if (block1.getClassName() === FlowGraphMeshPickEventBlock.ClassName) {
|
|
82
|
+
const mesh1 = block1._getReferencedMesh(context);
|
|
83
|
+
let i = 0;
|
|
84
|
+
for (; i < order.length; i++) {
|
|
85
|
+
const block2 = order[i];
|
|
86
|
+
const mesh2 = block2._getReferencedMesh(context);
|
|
87
|
+
if (mesh1 && mesh2 && _isADescendantOf(mesh1, mesh2)) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
order.splice(i, 0, block1);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
order.push(block1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return order;
|
|
98
|
+
}
|
|
74
99
|
/**
|
|
75
100
|
* Disposes of the flow graph. Cancels any pending tasks and removes all event listeners.
|
|
76
101
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowGraph.js","sourceRoot":"","sources":["../../../../dev/core/src/FlowGraph/flowGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAKpE,MAAM,CAAN,IAAY,cASX;AATD,WAAY,cAAc;IACtB;;OAEG;IACH,yDAAO,CAAA;IACP;;OAEG;IACH,yDAAO,CAAA;AACX,CAAC,EATW,cAAc,KAAd,cAAc,QASzB;AAgBD;;;;;;GAMG;AACH,MAAM,OAAO,SAAS;IAgBlB;;;OAG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,EAAE;gBACnC,KAAK,MAAM,oBAAoB,IAAI,MAAM,CAAC,iBAAiB,EAAE;oBACzD,MAAM,UAAU,GAAG,SAAS,CAAC,8BAA8B,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;oBAC1F,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;iBAChC;aACJ;YACD,IAAI,KAAK,YAAY,uBAAuB,EAAE;gBAC1C,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,aAAa,EAAE;oBACzC,KAAK,MAAM,oBAAoB,IAAI,SAAS,CAAC,iBAAiB,EAAE;wBAC5D,MAAM,UAAU,GAAG,SAAS,CAAC,+BAA+B,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;wBAC3F,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;qBACnC;iBACJ;aACJ;SACJ;QACD,KAAK,MAAM,iBAAiB,IAAI,mBAAmB,CAAC,iBAAiB,EAAE;YACnE,gBAAgB,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;SACxE;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import type { Observer } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { FlowGraphEventBlock } from \"./flowGraphEventBlock\";\r\nimport { FlowGraphContext } from \"./flowGraphContext\";\r\nimport { FlowGraphBlock } from \"./flowGraphBlock\";\r\nimport { FlowGraphExecutionBlock } from \"./flowGraphExecutionBlock\";\r\nimport type { FlowGraphCoordinator } from \"./flowGraphCoordinator\";\r\nimport type { FlowGraphSignalConnection } from \"./flowGraphSignalConnection\";\r\nimport type { FlowGraphDataConnection } from \"./flowGraphDataConnection\";\r\n\r\nexport enum FlowGraphState {\r\n /**\r\n * The graph is stopped\r\n */\r\n Stopped,\r\n /**\r\n * The graph is running\r\n */\r\n Started,\r\n}\r\n\r\n/**\r\n * @experimental\r\n * Parameters used to create a flow graph.\r\n */\r\nexport interface FlowGraphParams {\r\n /**\r\n * The scene that the flow graph belongs to.\r\n */\r\n scene: Scene;\r\n /**\r\n * The event coordinator used by the flow graph.\r\n */\r\n coordinator: FlowGraphCoordinator;\r\n}\r\n/**\r\n * @experimental\r\n * Class used to represent a flow graph.\r\n * A flow graph is a graph of blocks that can be used to create complex logic.\r\n * Blocks can be added to the graph and connected to each other.\r\n * The graph can then be started, which will init and start all of its event blocks.\r\n */\r\nexport class FlowGraph {\r\n /** @internal */\r\n public _eventBlocks: FlowGraphEventBlock[] = [];\r\n private _sceneDisposeObserver: Nullable<Observer<Scene>>;\r\n /**\r\n * @internal\r\n */\r\n public readonly _scene: Scene;\r\n private _coordinator: FlowGraphCoordinator;\r\n private _executionContexts: FlowGraphContext[] = [];\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n state: FlowGraphState = FlowGraphState.Stopped;\r\n\r\n /**\r\n * Construct a Flow Graph\r\n * @param params construction parameters. currently only the scene\r\n */\r\n public constructor(params: FlowGraphParams) {\r\n this._scene = params.scene;\r\n this._coordinator = params.coordinator;\r\n this._sceneDisposeObserver = this._scene.onDisposeObservable.add(() => this.dispose());\r\n }\r\n\r\n /**\r\n * Create a context. A context represents one self contained execution for the graph, with its own variables.\r\n * @returns the context, where you can get and set variables\r\n */\r\n public createContext() {\r\n const context = new FlowGraphContext({ scene: this._scene, coordinator: this._coordinator });\r\n this._executionContexts.push(context);\r\n return context;\r\n }\r\n\r\n /**\r\n * Add an event block. When the graph is started, it will start listening to events\r\n * from the block and execute the graph when they are triggered.\r\n * @param block\r\n */\r\n public addEventBlock(block: FlowGraphEventBlock): void {\r\n this._eventBlocks.push(block);\r\n }\r\n\r\n /**\r\n * Starts the flow graph. Initializes the event blocks and starts listening to events.\r\n */\r\n public start() {\r\n if (this.state === FlowGraphState.Started) {\r\n return;\r\n }\r\n this.state = FlowGraphState.Started;\r\n if (this._executionContexts.length === 0) {\r\n this.createContext();\r\n }\r\n for (const context of this._executionContexts) {\r\n for (const block of this._eventBlocks) {\r\n block._startPendingTasks(context);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the flow graph. Cancels any pending tasks and removes all event listeners.\r\n */\r\n public dispose() {\r\n if (this.state === FlowGraphState.Stopped) {\r\n return;\r\n }\r\n this.state = FlowGraphState.Stopped;\r\n for (const context of this._executionContexts) {\r\n context._clearPendingBlocks();\r\n }\r\n this._executionContexts.length = 0;\r\n this._eventBlocks.length = 0;\r\n this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);\r\n this._sceneDisposeObserver = null;\r\n }\r\n\r\n /**\r\n * Executes a function in all blocks of a flow graph, starting with the event blocks.\r\n * @param visitor the function to execute.\r\n */\r\n public visitAllBlocks(visitor: (block: FlowGraphBlock) => void) {\r\n const visitList: FlowGraphBlock[] = [];\r\n const idsAddedToVisitList = new Set<string>();\r\n for (const block of this._eventBlocks) {\r\n visitList.push(block);\r\n idsAddedToVisitList.add(block.uniqueId);\r\n }\r\n\r\n while (visitList.length > 0) {\r\n const block = visitList.pop()!;\r\n visitor(block);\r\n\r\n for (const dataIn of block.dataInputs) {\r\n for (const connection of dataIn._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalOut of block.signalOutputs) {\r\n for (const connection of signalOut._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Serializes a graph\r\n * @param serializationObject the object to write the values in\r\n * @param valueSerializeFunction a function to serialize complex values\r\n */\r\n public serialize(serializationObject: any = {}, valueSerializeFunction?: (key: string, value: any, serializationObject: any) => void) {\r\n serializationObject.variableDefinitions = {};\r\n serializationObject.allBlocks = [];\r\n this.visitAllBlocks((block) => {\r\n const serializedBlock: any = {};\r\n block.serialize(serializedBlock);\r\n serializationObject.allBlocks.push(serializedBlock);\r\n });\r\n serializationObject.executionContexts = [];\r\n for (const context of this._executionContexts) {\r\n const serializedContext: any = {};\r\n context.serialize(serializedContext, valueSerializeFunction);\r\n serializationObject.executionContexts.push(serializedContext);\r\n }\r\n }\r\n\r\n /**\r\n * Given a list of blocks, find an output data connection that has a specific unique id\r\n * @param blocks\r\n * @param uniqueId\r\n * @returns\r\n */\r\n public static GetDataOutConnectionByUniqueId(blocks: FlowGraphBlock[], uniqueId: string): FlowGraphDataConnection<any> {\r\n for (const block of blocks) {\r\n for (const dataOut of block.dataOutputs) {\r\n if (dataOut.uniqueId === uniqueId) {\r\n return dataOut;\r\n }\r\n }\r\n }\r\n throw new Error(\"Could not find data out connection with unique id \" + uniqueId);\r\n }\r\n\r\n /**\r\n * Given a list of blocks, find an input signal connection that has a specific unique id\r\n * @param blocks\r\n * @param uniqueId\r\n * @returns\r\n */\r\n public static GetSignalInConnectionByUniqueId(blocks: FlowGraphBlock[], uniqueId: string): FlowGraphSignalConnection {\r\n for (const block of blocks) {\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalIn of block.signalInputs) {\r\n if (signalIn.uniqueId === uniqueId) {\r\n return signalIn;\r\n }\r\n }\r\n }\r\n }\r\n throw new Error(\"Could not find signal in connection with unique id \" + uniqueId);\r\n }\r\n\r\n /**\r\n * Parses a graph from a given serialization object\r\n * @param serializationObject the object where the values are written\r\n * @param coordinator the flow graph coordinator\r\n * @param valueParseFunction a function to parse complex values in a scene\r\n * @returns\r\n */\r\n public static Parse(serializationObject: any, coordinator: FlowGraphCoordinator, valueParseFunction?: (key: string, serializationObject: any, scene: Scene) => any): FlowGraph {\r\n const graph = coordinator.createGraph();\r\n const blocks: FlowGraphBlock[] = [];\r\n // Parse all blocks\r\n for (const serializedBlock of serializationObject.allBlocks) {\r\n const block = FlowGraphBlock.Parse(serializedBlock);\r\n blocks.push(block);\r\n if (block instanceof FlowGraphEventBlock) {\r\n graph.addEventBlock(block);\r\n }\r\n }\r\n // After parsing all blocks, connect them\r\n for (const block of blocks) {\r\n for (const dataIn of block.dataInputs) {\r\n for (const serializedConnection of dataIn.connectedPointIds) {\r\n const connection = FlowGraph.GetDataOutConnectionByUniqueId(blocks, serializedConnection);\r\n dataIn.connectTo(connection);\r\n }\r\n }\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalOut of block.signalOutputs) {\r\n for (const serializedConnection of signalOut.connectedPointIds) {\r\n const connection = FlowGraph.GetSignalInConnectionByUniqueId(blocks, serializedConnection);\r\n signalOut.connectTo(connection);\r\n }\r\n }\r\n }\r\n }\r\n for (const serializedContext of serializationObject.executionContexts) {\r\n FlowGraphContext.Parse(serializedContext, graph, valueParseFunction);\r\n }\r\n return graph;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"flowGraph.js","sourceRoot":"","sources":["../../../../dev/core/src/FlowGraph/flowGraph.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAIpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,CAAN,IAAY,cASX;AATD,WAAY,cAAc;IACtB;;OAEG;IACH,yDAAO,CAAA;IACP;;OAEG;IACH,yDAAO,CAAA;AACX,CAAC,EATW,cAAc,KAAd,cAAc,QASzB;AAgBD;;;;;;GAMG;AACH,MAAM,OAAO,SAAS;IAgBlB;;;OAGG;IACH,YAAmB,MAAu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AS,CAAC,+BAA+B,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;wBAC3F,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;qBACnC;iBACJ;aACJ;SACJ;QACD,KAAK,MAAM,iBAAiB,IAAI,mBAAmB,CAAC,iBAAiB,EAAE;YACnE,gBAAgB,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;SACxE;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import type { Observer } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { FlowGraphEventBlock } from \"./flowGraphEventBlock\";\r\nimport { FlowGraphContext } from \"./flowGraphContext\";\r\nimport { FlowGraphBlock } from \"./flowGraphBlock\";\r\nimport { FlowGraphExecutionBlock } from \"./flowGraphExecutionBlock\";\r\nimport type { FlowGraphCoordinator } from \"./flowGraphCoordinator\";\r\nimport type { FlowGraphSignalConnection } from \"./flowGraphSignalConnection\";\r\nimport type { FlowGraphDataConnection } from \"./flowGraphDataConnection\";\r\nimport { FlowGraphMeshPickEventBlock } from \"./Blocks/Event/flowGraphMeshPickEventBlock\";\r\nimport { _isADescendantOf } from \"./utils\";\r\n\r\nexport enum FlowGraphState {\r\n /**\r\n * The graph is stopped\r\n */\r\n Stopped,\r\n /**\r\n * The graph is running\r\n */\r\n Started,\r\n}\r\n\r\n/**\r\n * @experimental\r\n * Parameters used to create a flow graph.\r\n */\r\nexport interface FlowGraphParams {\r\n /**\r\n * The scene that the flow graph belongs to.\r\n */\r\n scene: Scene;\r\n /**\r\n * The event coordinator used by the flow graph.\r\n */\r\n coordinator: FlowGraphCoordinator;\r\n}\r\n/**\r\n * @experimental\r\n * Class used to represent a flow graph.\r\n * A flow graph is a graph of blocks that can be used to create complex logic.\r\n * Blocks can be added to the graph and connected to each other.\r\n * The graph can then be started, which will init and start all of its event blocks.\r\n */\r\nexport class FlowGraph {\r\n /** @internal */\r\n public _eventBlocks: FlowGraphEventBlock[] = [];\r\n private _sceneDisposeObserver: Nullable<Observer<Scene>>;\r\n /**\r\n * @internal\r\n */\r\n public readonly _scene: Scene;\r\n private _coordinator: FlowGraphCoordinator;\r\n private _executionContexts: FlowGraphContext[] = [];\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n state: FlowGraphState = FlowGraphState.Stopped;\r\n\r\n /**\r\n * Construct a Flow Graph\r\n * @param params construction parameters. currently only the scene\r\n */\r\n public constructor(params: FlowGraphParams) {\r\n this._scene = params.scene;\r\n this._coordinator = params.coordinator;\r\n this._sceneDisposeObserver = this._scene.onDisposeObservable.add(() => this.dispose());\r\n }\r\n\r\n /**\r\n * Create a context. A context represents one self contained execution for the graph, with its own variables.\r\n * @returns the context, where you can get and set variables\r\n */\r\n public createContext() {\r\n const context = new FlowGraphContext({ scene: this._scene, coordinator: this._coordinator });\r\n this._executionContexts.push(context);\r\n return context;\r\n }\r\n\r\n /**\r\n * Add an event block. When the graph is started, it will start listening to events\r\n * from the block and execute the graph when they are triggered.\r\n * @param block\r\n */\r\n public addEventBlock(block: FlowGraphEventBlock): void {\r\n this._eventBlocks.push(block);\r\n }\r\n\r\n /**\r\n * Starts the flow graph. Initializes the event blocks and starts listening to events.\r\n */\r\n public start() {\r\n if (this.state === FlowGraphState.Started) {\r\n return;\r\n }\r\n this.state = FlowGraphState.Started;\r\n if (this._executionContexts.length === 0) {\r\n this.createContext();\r\n }\r\n for (const context of this._executionContexts) {\r\n const contextualOrder = this._getContextualOrder(context);\r\n for (const block of contextualOrder) {\r\n block._startPendingTasks(context);\r\n }\r\n }\r\n }\r\n\r\n private _getContextualOrder(context: FlowGraphContext): FlowGraphEventBlock[] {\r\n const order: FlowGraphEventBlock[] = [];\r\n\r\n for (const block1 of this._eventBlocks) {\r\n // If the block is a mesh pick, guarantee that picks of children meshes come before picks of parent meshes\r\n if (block1.getClassName() === FlowGraphMeshPickEventBlock.ClassName) {\r\n const mesh1 = (block1 as FlowGraphMeshPickEventBlock)._getReferencedMesh(context);\r\n let i = 0;\r\n for (; i < order.length; i++) {\r\n const block2 = order[i];\r\n const mesh2 = (block2 as FlowGraphMeshPickEventBlock)._getReferencedMesh(context);\r\n if (mesh1 && mesh2 && _isADescendantOf(mesh1, mesh2)) {\r\n break;\r\n }\r\n }\r\n order.splice(i, 0, block1);\r\n } else {\r\n order.push(block1);\r\n }\r\n }\r\n return order;\r\n }\r\n\r\n /**\r\n * Disposes of the flow graph. Cancels any pending tasks and removes all event listeners.\r\n */\r\n public dispose() {\r\n if (this.state === FlowGraphState.Stopped) {\r\n return;\r\n }\r\n this.state = FlowGraphState.Stopped;\r\n for (const context of this._executionContexts) {\r\n context._clearPendingBlocks();\r\n }\r\n this._executionContexts.length = 0;\r\n this._eventBlocks.length = 0;\r\n this._scene.onDisposeObservable.remove(this._sceneDisposeObserver);\r\n this._sceneDisposeObserver = null;\r\n }\r\n\r\n /**\r\n * Executes a function in all blocks of a flow graph, starting with the event blocks.\r\n * @param visitor the function to execute.\r\n */\r\n public visitAllBlocks(visitor: (block: FlowGraphBlock) => void) {\r\n const visitList: FlowGraphBlock[] = [];\r\n const idsAddedToVisitList = new Set<string>();\r\n for (const block of this._eventBlocks) {\r\n visitList.push(block);\r\n idsAddedToVisitList.add(block.uniqueId);\r\n }\r\n\r\n while (visitList.length > 0) {\r\n const block = visitList.pop()!;\r\n visitor(block);\r\n\r\n for (const dataIn of block.dataInputs) {\r\n for (const connection of dataIn._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalOut of block.signalOutputs) {\r\n for (const connection of signalOut._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Serializes a graph\r\n * @param serializationObject the object to write the values in\r\n * @param valueSerializeFunction a function to serialize complex values\r\n */\r\n public serialize(serializationObject: any = {}, valueSerializeFunction?: (key: string, value: any, serializationObject: any) => void) {\r\n serializationObject.variableDefinitions = {};\r\n serializationObject.allBlocks = [];\r\n this.visitAllBlocks((block) => {\r\n const serializedBlock: any = {};\r\n block.serialize(serializedBlock);\r\n serializationObject.allBlocks.push(serializedBlock);\r\n });\r\n serializationObject.executionContexts = [];\r\n for (const context of this._executionContexts) {\r\n const serializedContext: any = {};\r\n context.serialize(serializedContext, valueSerializeFunction);\r\n serializationObject.executionContexts.push(serializedContext);\r\n }\r\n }\r\n\r\n /**\r\n * Given a list of blocks, find an output data connection that has a specific unique id\r\n * @param blocks\r\n * @param uniqueId\r\n * @returns\r\n */\r\n public static GetDataOutConnectionByUniqueId(blocks: FlowGraphBlock[], uniqueId: string): FlowGraphDataConnection<any> {\r\n for (const block of blocks) {\r\n for (const dataOut of block.dataOutputs) {\r\n if (dataOut.uniqueId === uniqueId) {\r\n return dataOut;\r\n }\r\n }\r\n }\r\n throw new Error(\"Could not find data out connection with unique id \" + uniqueId);\r\n }\r\n\r\n /**\r\n * Given a list of blocks, find an input signal connection that has a specific unique id\r\n * @param blocks\r\n * @param uniqueId\r\n * @returns\r\n */\r\n public static GetSignalInConnectionByUniqueId(blocks: FlowGraphBlock[], uniqueId: string): FlowGraphSignalConnection {\r\n for (const block of blocks) {\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalIn of block.signalInputs) {\r\n if (signalIn.uniqueId === uniqueId) {\r\n return signalIn;\r\n }\r\n }\r\n }\r\n }\r\n throw new Error(\"Could not find signal in connection with unique id \" + uniqueId);\r\n }\r\n\r\n /**\r\n * Parses a graph from a given serialization object\r\n * @param serializationObject the object where the values are written\r\n * @param coordinator the flow graph coordinator\r\n * @param valueParseFunction a function to parse complex values in a scene\r\n * @returns\r\n */\r\n public static Parse(serializationObject: any, coordinator: FlowGraphCoordinator, valueParseFunction?: (key: string, serializationObject: any, scene: Scene) => any): FlowGraph {\r\n const graph = coordinator.createGraph();\r\n const blocks: FlowGraphBlock[] = [];\r\n // Parse all blocks\r\n for (const serializedBlock of serializationObject.allBlocks) {\r\n const block = FlowGraphBlock.Parse(serializedBlock);\r\n blocks.push(block);\r\n if (block instanceof FlowGraphEventBlock) {\r\n graph.addEventBlock(block);\r\n }\r\n }\r\n // After parsing all blocks, connect them\r\n for (const block of blocks) {\r\n for (const dataIn of block.dataInputs) {\r\n for (const serializedConnection of dataIn.connectedPointIds) {\r\n const connection = FlowGraph.GetDataOutConnectionByUniqueId(blocks, serializedConnection);\r\n dataIn.connectTo(connection);\r\n }\r\n }\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalOut of block.signalOutputs) {\r\n for (const serializedConnection of signalOut.connectedPointIds) {\r\n const connection = FlowGraph.GetSignalInConnectionByUniqueId(blocks, serializedConnection);\r\n signalOut.connectTo(connection);\r\n }\r\n }\r\n }\r\n }\r\n for (const serializedContext of serializationObject.executionContexts) {\r\n FlowGraphContext.Parse(serializedContext, graph, valueParseFunction);\r\n }\r\n return graph;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Returns if mesh1 is a descendant of mesh2
|
|
4
|
+
* @param mesh1
|
|
5
|
+
* @param mesh2
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function _isADescendantOf(mesh1, mesh2) {
|
|
9
|
+
return !!(mesh1.parent && (mesh1.parent === mesh2 || _isADescendantOf(mesh1.parent, mesh2)));
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../dev/core/src/FlowGraph/utils.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAW,EAAE,KAAW;IACrD,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,IAAI,gBAAgB,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import type { Node } from \"../node\";\r\n\r\n/**\r\n * @internal\r\n * Returns if mesh1 is a descendant of mesh2\r\n * @param mesh1\r\n * @param mesh2\r\n * @returns\r\n */\r\nexport function _isADescendantOf(mesh1: Node, mesh2: Node): boolean {\r\n return !!(mesh1.parent && (mesh1.parent === mesh2 || _isADescendantOf(mesh1.parent, mesh2)));\r\n}\r\n"]}
|
package/Gizmos/axisDragGizmo.js
CHANGED
|
@@ -153,7 +153,7 @@ export class AxisDragGizmo extends Gizmo {
|
|
|
153
153
|
if (this.dragBehavior.validateDrag(TmpVectors.Vector3[2])) {
|
|
154
154
|
this.attachedNode.getWorldMatrix().addTranslationFromFloats(TmpVectors.Vector3[1].x, TmpVectors.Vector3[1].y, TmpVectors.Vector3[1].z);
|
|
155
155
|
this.attachedNode.updateCache();
|
|
156
|
-
tmpSnapEvent.snapDistance = this.snapDistance * dragSteps;
|
|
156
|
+
tmpSnapEvent.snapDistance = this.snapDistance * dragSteps * Math.sign(currentSnapDragDistance);
|
|
157
157
|
this.onSnapObservable.notifyObservers(tmpSnapEvent);
|
|
158
158
|
matrixChanged = true;
|
|
159
159
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axisDragGizmo.js","sourceRoot":"","sources":["../../../../dev/core/src/Gizmos/axisDragGizmo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,IAAI,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CAAC,CAAC;QACpF,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC7B;QACD,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACjF,IAAI,IAAI,EAAE;gBACN,IAAI,CAAC,OAAO,EAAE,CAAC;aAClB;QACL,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["import type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { PointerInfo } from \"../Events/pointerEvents\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport { TransformNode } from \"../Meshes/transformNode\";\r\nimport type { Node } from \"../node\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { CreateCylinder } from \"../Meshes/Builders/cylinderBuilder\";\r\nimport { PointerDragBehavior } from \"../Behaviors/Meshes/pointerDragBehavior\";\r\nimport type { GizmoAxisCache, IGizmo } from \"./gizmo\";\r\nimport { Gizmo } from \"./gizmo\";\r\nimport { UtilityLayerRenderer } from \"../Rendering/utilityLayerRenderer\";\r\nimport { StandardMaterial } from \"../Materials/standardMaterial\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { PositionGizmo } from \"./positionGizmo\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport { TmpVectors } from \"../Maths/math.vector\";\r\n\r\n/**\r\n * Interface for axis drag gizmo\r\n */\r\nexport interface IAxisDragGizmo extends IGizmo {\r\n /** Drag behavior responsible for the gizmos dragging interactions */\r\n dragBehavior: PointerDragBehavior;\r\n /** Drag distance in babylon units that the gizmo will snap to when dragged */\r\n snapDistance: number;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the change in distance\r\n */\r\n onSnapObservable: Observable<{ snapDistance: number }>;\r\n /** If the gizmo is enabled */\r\n isEnabled: boolean;\r\n\r\n /** Default material used to render when gizmo is not disabled or hovered */\r\n coloredMaterial: StandardMaterial;\r\n /** Material used to render when gizmo is hovered with mouse*/\r\n hoverMaterial: StandardMaterial;\r\n /** Material used to render when gizmo is disabled. typically grey.*/\r\n disableMaterial: StandardMaterial;\r\n}\r\n\r\n/**\r\n * Single axis drag gizmo\r\n */\r\nexport class AxisDragGizmo extends Gizmo implements IAxisDragGizmo {\r\n /**\r\n * Drag behavior responsible for the gizmos dragging interactions\r\n */\r\n public dragBehavior: PointerDragBehavior;\r\n protected _pointerObserver: Nullable<Observer<PointerInfo>> = null;\r\n /**\r\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public snapDistance = 0;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the change in distance\r\n */\r\n public onSnapObservable = new Observable<{ snapDistance: number }>();\r\n\r\n protected _isEnabled: boolean = true;\r\n protected _parent: Nullable<PositionGizmo> = null;\r\n\r\n protected _gizmoMesh: Mesh;\r\n protected _coloredMaterial: StandardMaterial;\r\n protected _hoverMaterial: StandardMaterial;\r\n protected _disableMaterial: StandardMaterial;\r\n protected _dragging: boolean = false;\r\n\r\n /** Default material used to render when gizmo is not disabled or hovered */\r\n public get coloredMaterial() {\r\n return this._coloredMaterial;\r\n }\r\n\r\n /** Material used to render when gizmo is hovered with mouse*/\r\n public get hoverMaterial() {\r\n return this._hoverMaterial;\r\n }\r\n\r\n /** Material used to render when gizmo is disabled. typically grey.*/\r\n public get disableMaterial() {\r\n return this._disableMaterial;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _CreateArrow(scene: Scene, material: StandardMaterial, thickness: number = 1, isCollider = false): TransformNode {\r\n const arrow = new TransformNode(\"arrow\", scene);\r\n const cylinder = CreateCylinder(\r\n \"cylinder\",\r\n {\r\n diameterTop: 0,\r\n height: 0.075,\r\n diameterBottom: 0.0375 * (1 + (thickness - 1) / 4),\r\n tessellation: 96,\r\n },\r\n scene\r\n );\r\n const line = CreateCylinder(\r\n \"cylinder\",\r\n {\r\n diameterTop: 0.005 * thickness,\r\n height: 0.275,\r\n diameterBottom: 0.005 * thickness,\r\n tessellation: 96,\r\n },\r\n scene\r\n );\r\n\r\n // Position arrow pointing in its drag axis\r\n cylinder.parent = arrow;\r\n cylinder.material = material;\r\n cylinder.rotation.x = Math.PI / 2;\r\n cylinder.position.z += 0.3;\r\n\r\n line.parent = arrow;\r\n line.material = material;\r\n line.position.z += 0.275 / 2;\r\n line.rotation.x = Math.PI / 2;\r\n\r\n if (isCollider) {\r\n line.visibility = 0;\r\n cylinder.visibility = 0;\r\n }\r\n return arrow;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _CreateArrowInstance(scene: Scene, arrow: TransformNode): TransformNode {\r\n const instance = new TransformNode(\"arrow\", scene);\r\n for (const mesh of arrow.getChildMeshes()) {\r\n const childInstance = (mesh as Mesh).createInstance(mesh.name);\r\n childInstance.parent = instance;\r\n }\r\n return instance;\r\n }\r\n\r\n /**\r\n * Creates an AxisDragGizmo\r\n * @param dragAxis The axis which the gizmo will be able to drag on\r\n * @param color The color of the gizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param parent\r\n * @param thickness display gizmo axis thickness\r\n * @param hoverColor The color of the gizmo when hovering over and dragging\r\n * @param disableColor The Color of the gizmo when its disabled\r\n */\r\n constructor(\r\n dragAxis: Vector3,\r\n color: Color3 = Color3.Gray(),\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer,\r\n parent: Nullable<PositionGizmo> = null,\r\n thickness: number = 1,\r\n hoverColor: Color3 = Color3.Yellow(),\r\n disableColor: Color3 = Color3.Gray()\r\n ) {\r\n super(gizmoLayer);\r\n this._parent = parent;\r\n\r\n // Create Material\r\n this._coloredMaterial = new StandardMaterial(\"\", gizmoLayer.utilityLayerScene);\r\n this._coloredMaterial.diffuseColor = color;\r\n this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\r\n\r\n this._hoverMaterial = new StandardMaterial(\"\", gizmoLayer.utilityLayerScene);\r\n this._hoverMaterial.diffuseColor = hoverColor;\r\n\r\n this._disableMaterial = new StandardMaterial(\"\", gizmoLayer.utilityLayerScene);\r\n this._disableMaterial.diffuseColor = disableColor;\r\n this._disableMaterial.alpha = 0.4;\r\n\r\n // Build Mesh + Collider\r\n const arrow = AxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, this._coloredMaterial, thickness);\r\n const collider = AxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, this._coloredMaterial, thickness + 4, true);\r\n\r\n // Add to Root Node\r\n this._gizmoMesh = new Mesh(\"\", gizmoLayer.utilityLayerScene);\r\n this._gizmoMesh.addChild(arrow as Mesh);\r\n this._gizmoMesh.addChild(collider as Mesh);\r\n\r\n this._gizmoMesh.lookAt(this._rootMesh.position.add(dragAxis));\r\n this._gizmoMesh.scaling.scaleInPlace(1 / 3);\r\n this._gizmoMesh.parent = this._rootMesh;\r\n\r\n let currentSnapDragDistance = 0;\r\n const tmpSnapEvent = { snapDistance: 0 };\r\n // Add drag behavior to handle events when the gizmo is dragged\r\n this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });\r\n this.dragBehavior.moveAttached = false;\r\n this.dragBehavior.updateDragPlane = false;\r\n this._rootMesh.addBehavior(this.dragBehavior);\r\n\r\n this.dragBehavior.onDragObservable.add((event) => {\r\n if (this.attachedNode) {\r\n // Keep world translation and use it to update world transform\r\n // if the node has parent, the local transform properties (position, rotation, scale)\r\n // will be recomputed in _matrixChanged function\r\n\r\n let matrixChanged: boolean = false;\r\n // Snapping logic\r\n if (this.snapDistance == 0) {\r\n this.attachedNode.getWorldMatrix().getTranslationToRef(TmpVectors.Vector3[2]);\r\n TmpVectors.Vector3[2].addInPlace(event.delta);\r\n if (this.dragBehavior.validateDrag(TmpVectors.Vector3[2])) {\r\n if ((this.attachedNode as any).position) {\r\n // Required for nodes like lights\r\n (this.attachedNode as any).position.addInPlaceFromFloats(event.delta.x, event.delta.y, event.delta.z);\r\n }\r\n\r\n // use _worldMatrix to not force a matrix update when calling GetWorldMatrix especially with Cameras\r\n this.attachedNode.getWorldMatrix().addTranslationFromFloats(event.delta.x, event.delta.y, event.delta.z);\r\n this.attachedNode.updateCache();\r\n matrixChanged = true;\r\n }\r\n } else {\r\n currentSnapDragDistance += event.dragDistance;\r\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\r\n const dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\r\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\r\n event.delta.normalizeToRef(TmpVectors.Vector3[1]);\r\n TmpVectors.Vector3[1].scaleInPlace(this.snapDistance * dragSteps);\r\n\r\n this.attachedNode.getWorldMatrix().getTranslationToRef(TmpVectors.Vector3[2]);\r\n TmpVectors.Vector3[2].addInPlace(TmpVectors.Vector3[1]);\r\n if (this.dragBehavior.validateDrag(TmpVectors.Vector3[2])) {\r\n this.attachedNode.getWorldMatrix().addTranslationFromFloats(TmpVectors.Vector3[1].x, TmpVectors.Vector3[1].y, TmpVectors.Vector3[1].z);\r\n this.attachedNode.updateCache();\r\n tmpSnapEvent.snapDistance = this.snapDistance * dragSteps;\r\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\r\n matrixChanged = true;\r\n }\r\n }\r\n }\r\n if (matrixChanged) {\r\n this._matrixChanged();\r\n }\r\n }\r\n });\r\n this.dragBehavior.onDragStartObservable.add(() => {\r\n this._dragging = true;\r\n });\r\n this.dragBehavior.onDragEndObservable.add(() => {\r\n this._dragging = false;\r\n });\r\n\r\n const light = gizmoLayer._getSharedGizmoLight();\r\n light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));\r\n\r\n const cache: GizmoAxisCache = {\r\n gizmoMeshes: arrow.getChildMeshes() as Mesh[],\r\n colliderMeshes: collider.getChildMeshes() as Mesh[],\r\n material: this._coloredMaterial,\r\n hoverMaterial: this._hoverMaterial,\r\n disableMaterial: this._disableMaterial,\r\n active: false,\r\n dragBehavior: this.dragBehavior,\r\n };\r\n this._parent?.addToAxisCache(collider as Mesh, cache);\r\n\r\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {\r\n if (this._customMeshSet) {\r\n return;\r\n }\r\n this._isHovered = !!(cache.colliderMeshes.indexOf(<Mesh>pointerInfo?.pickInfo?.pickedMesh) != -1);\r\n if (!this._parent) {\r\n const material = this.dragBehavior.enabled ? (this._isHovered || this._dragging ? this._hoverMaterial : this._coloredMaterial) : this._disableMaterial;\r\n this._setGizmoMeshMaterial(cache.gizmoMeshes, material);\r\n }\r\n });\r\n\r\n this.dragBehavior.onEnabledObservable.add((newState) => {\r\n this._setGizmoMeshMaterial(cache.gizmoMeshes, newState ? cache.material : cache.disableMaterial);\r\n });\r\n }\r\n\r\n protected _attachedNodeChanged(value: Nullable<Node>) {\r\n if (this.dragBehavior) {\r\n this.dragBehavior.enabled = value ? true : false;\r\n }\r\n }\r\n\r\n /**\r\n * If the gizmo is enabled\r\n */\r\n public set isEnabled(value: boolean) {\r\n this._isEnabled = value;\r\n if (!value) {\r\n this.attachedMesh = null;\r\n this.attachedNode = null;\r\n } else {\r\n if (this._parent) {\r\n this.attachedMesh = this._parent.attachedMesh;\r\n this.attachedNode = this._parent.attachedNode;\r\n }\r\n }\r\n }\r\n\r\n public get isEnabled(): boolean {\r\n return this._isEnabled;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this.onSnapObservable.clear();\r\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\r\n this.dragBehavior.detach();\r\n if (this._gizmoMesh) {\r\n this._gizmoMesh.dispose();\r\n }\r\n [this._coloredMaterial, this._hoverMaterial, this._disableMaterial].forEach((matl) => {\r\n if (matl) {\r\n matl.dispose();\r\n }\r\n });\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"axisDragGizmo.js","sourceRoot":"","sources":["../../../../dev/core/src/Gizmos/axisDragGizmo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AA0BlD;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAyBpC,4EAA4E;IAC5E,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;IAED,8DAA8D;IAC9D,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED,qEAAqE;IACrE,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,YAAY,CAAC,KAAY,EAAE,QAA0B,EAAE,YAAoB,CAAC,EAAE,UAAU,GAAG,KAAK;QAC1G,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,QAAQ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E;gBACd,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC9C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;aACjD;SACJ;IACL,CAAC;IAED,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACpF,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC7B;QACD,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACjF,IAAI,IAAI,EAAE;gBACN,IAAI,CAAC,OAAO,EAAE,CAAC;aAClB;QACL,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["import type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { PointerInfo } from \"../Events/pointerEvents\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport { TransformNode } from \"../Meshes/transformNode\";\r\nimport type { Node } from \"../node\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { CreateCylinder } from \"../Meshes/Builders/cylinderBuilder\";\r\nimport { PointerDragBehavior } from \"../Behaviors/Meshes/pointerDragBehavior\";\r\nimport type { GizmoAxisCache, IGizmo } from \"./gizmo\";\r\nimport { Gizmo } from \"./gizmo\";\r\nimport { UtilityLayerRenderer } from \"../Rendering/utilityLayerRenderer\";\r\nimport { StandardMaterial } from \"../Materials/standardMaterial\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { PositionGizmo } from \"./positionGizmo\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport { TmpVectors } from \"../Maths/math.vector\";\r\n\r\n/**\r\n * Interface for axis drag gizmo\r\n */\r\nexport interface IAxisDragGizmo extends IGizmo {\r\n /** Drag behavior responsible for the gizmos dragging interactions */\r\n dragBehavior: PointerDragBehavior;\r\n /** Drag distance in babylon units that the gizmo will snap to when dragged */\r\n snapDistance: number;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the change in distance\r\n */\r\n onSnapObservable: Observable<{ snapDistance: number }>;\r\n /** If the gizmo is enabled */\r\n isEnabled: boolean;\r\n\r\n /** Default material used to render when gizmo is not disabled or hovered */\r\n coloredMaterial: StandardMaterial;\r\n /** Material used to render when gizmo is hovered with mouse*/\r\n hoverMaterial: StandardMaterial;\r\n /** Material used to render when gizmo is disabled. typically grey.*/\r\n disableMaterial: StandardMaterial;\r\n}\r\n\r\n/**\r\n * Single axis drag gizmo\r\n */\r\nexport class AxisDragGizmo extends Gizmo implements IAxisDragGizmo {\r\n /**\r\n * Drag behavior responsible for the gizmos dragging interactions\r\n */\r\n public dragBehavior: PointerDragBehavior;\r\n protected _pointerObserver: Nullable<Observer<PointerInfo>> = null;\r\n /**\r\n * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)\r\n */\r\n public snapDistance = 0;\r\n /**\r\n * Event that fires each time the gizmo snaps to a new location.\r\n * * snapDistance is the change in distance\r\n */\r\n public onSnapObservable = new Observable<{ snapDistance: number }>();\r\n\r\n protected _isEnabled: boolean = true;\r\n protected _parent: Nullable<PositionGizmo> = null;\r\n\r\n protected _gizmoMesh: Mesh;\r\n protected _coloredMaterial: StandardMaterial;\r\n protected _hoverMaterial: StandardMaterial;\r\n protected _disableMaterial: StandardMaterial;\r\n protected _dragging: boolean = false;\r\n\r\n /** Default material used to render when gizmo is not disabled or hovered */\r\n public get coloredMaterial() {\r\n return this._coloredMaterial;\r\n }\r\n\r\n /** Material used to render when gizmo is hovered with mouse*/\r\n public get hoverMaterial() {\r\n return this._hoverMaterial;\r\n }\r\n\r\n /** Material used to render when gizmo is disabled. typically grey.*/\r\n public get disableMaterial() {\r\n return this._disableMaterial;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _CreateArrow(scene: Scene, material: StandardMaterial, thickness: number = 1, isCollider = false): TransformNode {\r\n const arrow = new TransformNode(\"arrow\", scene);\r\n const cylinder = CreateCylinder(\r\n \"cylinder\",\r\n {\r\n diameterTop: 0,\r\n height: 0.075,\r\n diameterBottom: 0.0375 * (1 + (thickness - 1) / 4),\r\n tessellation: 96,\r\n },\r\n scene\r\n );\r\n const line = CreateCylinder(\r\n \"cylinder\",\r\n {\r\n diameterTop: 0.005 * thickness,\r\n height: 0.275,\r\n diameterBottom: 0.005 * thickness,\r\n tessellation: 96,\r\n },\r\n scene\r\n );\r\n\r\n // Position arrow pointing in its drag axis\r\n cylinder.parent = arrow;\r\n cylinder.material = material;\r\n cylinder.rotation.x = Math.PI / 2;\r\n cylinder.position.z += 0.3;\r\n\r\n line.parent = arrow;\r\n line.material = material;\r\n line.position.z += 0.275 / 2;\r\n line.rotation.x = Math.PI / 2;\r\n\r\n if (isCollider) {\r\n line.visibility = 0;\r\n cylinder.visibility = 0;\r\n }\r\n return arrow;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static _CreateArrowInstance(scene: Scene, arrow: TransformNode): TransformNode {\r\n const instance = new TransformNode(\"arrow\", scene);\r\n for (const mesh of arrow.getChildMeshes()) {\r\n const childInstance = (mesh as Mesh).createInstance(mesh.name);\r\n childInstance.parent = instance;\r\n }\r\n return instance;\r\n }\r\n\r\n /**\r\n * Creates an AxisDragGizmo\r\n * @param dragAxis The axis which the gizmo will be able to drag on\r\n * @param color The color of the gizmo\r\n * @param gizmoLayer The utility layer the gizmo will be added to\r\n * @param parent\r\n * @param thickness display gizmo axis thickness\r\n * @param hoverColor The color of the gizmo when hovering over and dragging\r\n * @param disableColor The Color of the gizmo when its disabled\r\n */\r\n constructor(\r\n dragAxis: Vector3,\r\n color: Color3 = Color3.Gray(),\r\n gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer,\r\n parent: Nullable<PositionGizmo> = null,\r\n thickness: number = 1,\r\n hoverColor: Color3 = Color3.Yellow(),\r\n disableColor: Color3 = Color3.Gray()\r\n ) {\r\n super(gizmoLayer);\r\n this._parent = parent;\r\n\r\n // Create Material\r\n this._coloredMaterial = new StandardMaterial(\"\", gizmoLayer.utilityLayerScene);\r\n this._coloredMaterial.diffuseColor = color;\r\n this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));\r\n\r\n this._hoverMaterial = new StandardMaterial(\"\", gizmoLayer.utilityLayerScene);\r\n this._hoverMaterial.diffuseColor = hoverColor;\r\n\r\n this._disableMaterial = new StandardMaterial(\"\", gizmoLayer.utilityLayerScene);\r\n this._disableMaterial.diffuseColor = disableColor;\r\n this._disableMaterial.alpha = 0.4;\r\n\r\n // Build Mesh + Collider\r\n const arrow = AxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, this._coloredMaterial, thickness);\r\n const collider = AxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, this._coloredMaterial, thickness + 4, true);\r\n\r\n // Add to Root Node\r\n this._gizmoMesh = new Mesh(\"\", gizmoLayer.utilityLayerScene);\r\n this._gizmoMesh.addChild(arrow as Mesh);\r\n this._gizmoMesh.addChild(collider as Mesh);\r\n\r\n this._gizmoMesh.lookAt(this._rootMesh.position.add(dragAxis));\r\n this._gizmoMesh.scaling.scaleInPlace(1 / 3);\r\n this._gizmoMesh.parent = this._rootMesh;\r\n\r\n let currentSnapDragDistance = 0;\r\n const tmpSnapEvent = { snapDistance: 0 };\r\n // Add drag behavior to handle events when the gizmo is dragged\r\n this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });\r\n this.dragBehavior.moveAttached = false;\r\n this.dragBehavior.updateDragPlane = false;\r\n this._rootMesh.addBehavior(this.dragBehavior);\r\n\r\n this.dragBehavior.onDragObservable.add((event) => {\r\n if (this.attachedNode) {\r\n // Keep world translation and use it to update world transform\r\n // if the node has parent, the local transform properties (position, rotation, scale)\r\n // will be recomputed in _matrixChanged function\r\n\r\n let matrixChanged: boolean = false;\r\n // Snapping logic\r\n if (this.snapDistance == 0) {\r\n this.attachedNode.getWorldMatrix().getTranslationToRef(TmpVectors.Vector3[2]);\r\n TmpVectors.Vector3[2].addInPlace(event.delta);\r\n if (this.dragBehavior.validateDrag(TmpVectors.Vector3[2])) {\r\n if ((this.attachedNode as any).position) {\r\n // Required for nodes like lights\r\n (this.attachedNode as any).position.addInPlaceFromFloats(event.delta.x, event.delta.y, event.delta.z);\r\n }\r\n\r\n // use _worldMatrix to not force a matrix update when calling GetWorldMatrix especially with Cameras\r\n this.attachedNode.getWorldMatrix().addTranslationFromFloats(event.delta.x, event.delta.y, event.delta.z);\r\n this.attachedNode.updateCache();\r\n matrixChanged = true;\r\n }\r\n } else {\r\n currentSnapDragDistance += event.dragDistance;\r\n if (Math.abs(currentSnapDragDistance) > this.snapDistance) {\r\n const dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);\r\n currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;\r\n event.delta.normalizeToRef(TmpVectors.Vector3[1]);\r\n TmpVectors.Vector3[1].scaleInPlace(this.snapDistance * dragSteps);\r\n\r\n this.attachedNode.getWorldMatrix().getTranslationToRef(TmpVectors.Vector3[2]);\r\n TmpVectors.Vector3[2].addInPlace(TmpVectors.Vector3[1]);\r\n if (this.dragBehavior.validateDrag(TmpVectors.Vector3[2])) {\r\n this.attachedNode.getWorldMatrix().addTranslationFromFloats(TmpVectors.Vector3[1].x, TmpVectors.Vector3[1].y, TmpVectors.Vector3[1].z);\r\n this.attachedNode.updateCache();\r\n tmpSnapEvent.snapDistance = this.snapDistance * dragSteps * Math.sign(currentSnapDragDistance);\r\n this.onSnapObservable.notifyObservers(tmpSnapEvent);\r\n matrixChanged = true;\r\n }\r\n }\r\n }\r\n if (matrixChanged) {\r\n this._matrixChanged();\r\n }\r\n }\r\n });\r\n this.dragBehavior.onDragStartObservable.add(() => {\r\n this._dragging = true;\r\n });\r\n this.dragBehavior.onDragEndObservable.add(() => {\r\n this._dragging = false;\r\n });\r\n\r\n const light = gizmoLayer._getSharedGizmoLight();\r\n light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));\r\n\r\n const cache: GizmoAxisCache = {\r\n gizmoMeshes: arrow.getChildMeshes() as Mesh[],\r\n colliderMeshes: collider.getChildMeshes() as Mesh[],\r\n material: this._coloredMaterial,\r\n hoverMaterial: this._hoverMaterial,\r\n disableMaterial: this._disableMaterial,\r\n active: false,\r\n dragBehavior: this.dragBehavior,\r\n };\r\n this._parent?.addToAxisCache(collider as Mesh, cache);\r\n\r\n this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {\r\n if (this._customMeshSet) {\r\n return;\r\n }\r\n this._isHovered = !!(cache.colliderMeshes.indexOf(<Mesh>pointerInfo?.pickInfo?.pickedMesh) != -1);\r\n if (!this._parent) {\r\n const material = this.dragBehavior.enabled ? (this._isHovered || this._dragging ? this._hoverMaterial : this._coloredMaterial) : this._disableMaterial;\r\n this._setGizmoMeshMaterial(cache.gizmoMeshes, material);\r\n }\r\n });\r\n\r\n this.dragBehavior.onEnabledObservable.add((newState) => {\r\n this._setGizmoMeshMaterial(cache.gizmoMeshes, newState ? cache.material : cache.disableMaterial);\r\n });\r\n }\r\n\r\n protected _attachedNodeChanged(value: Nullable<Node>) {\r\n if (this.dragBehavior) {\r\n this.dragBehavior.enabled = value ? true : false;\r\n }\r\n }\r\n\r\n /**\r\n * If the gizmo is enabled\r\n */\r\n public set isEnabled(value: boolean) {\r\n this._isEnabled = value;\r\n if (!value) {\r\n this.attachedMesh = null;\r\n this.attachedNode = null;\r\n } else {\r\n if (this._parent) {\r\n this.attachedMesh = this._parent.attachedMesh;\r\n this.attachedNode = this._parent.attachedNode;\r\n }\r\n }\r\n }\r\n\r\n public get isEnabled(): boolean {\r\n return this._isEnabled;\r\n }\r\n\r\n /**\r\n * Disposes of the gizmo\r\n */\r\n public dispose() {\r\n this.onSnapObservable.clear();\r\n this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);\r\n this.dragBehavior.detach();\r\n if (this._gizmoMesh) {\r\n this._gizmoMesh.dispose();\r\n }\r\n [this._coloredMaterial, this._hoverMaterial, this._disableMaterial].forEach((matl) => {\r\n if (matl) {\r\n matl.dispose();\r\n }\r\n });\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -21,6 +21,8 @@ export interface IAxisScaleGizmo extends IGizmo {
|
|
|
21
21
|
dragBehavior: PointerDragBehavior;
|
|
22
22
|
/** Drag distance in babylon units that the gizmo will snap to when dragged */
|
|
23
23
|
snapDistance: number;
|
|
24
|
+
/** Incremental snap scaling. When true, with a snapDistance of 0.1, scaling will be 1.1,1.2,1.3 instead of, when false: 1.1,1.21,1.33,... */
|
|
25
|
+
incrementalSnap: boolean;
|
|
24
26
|
/**
|
|
25
27
|
* Event that fires each time the gizmo snaps to a new location.
|
|
26
28
|
* * snapDistance is the change in distance
|
|
@@ -75,6 +77,14 @@ export declare class AxisScaleGizmo extends Gizmo implements IAxisScaleGizmo {
|
|
|
75
77
|
* The magnitude of the drag strength (scaling factor)
|
|
76
78
|
*/
|
|
77
79
|
dragScale: number;
|
|
80
|
+
/**
|
|
81
|
+
* The minimal absolute scale per component. can be positive or negative but never smaller.
|
|
82
|
+
*/
|
|
83
|
+
static MinimumAbsoluteScale: number;
|
|
84
|
+
/**
|
|
85
|
+
* Incremental snap scaling (default is false). When true, with a snapDistance of 0.1, scaling will be 1.1,1.2,1.3 instead of, when false: 1.1,1.21,1.33,...
|
|
86
|
+
*/
|
|
87
|
+
incrementalSnap: boolean;
|
|
78
88
|
protected _isEnabled: boolean;
|
|
79
89
|
protected _parent: Nullable<ScaleGizmo>;
|
|
80
90
|
protected _gizmoMesh: Mesh;
|
|
@@ -96,8 +106,10 @@ export declare class AxisScaleGizmo extends Gizmo implements IAxisScaleGizmo {
|
|
|
96
106
|
* @param gizmoLayer The utility layer the gizmo will be added to
|
|
97
107
|
* @param parent
|
|
98
108
|
* @param thickness display gizmo axis thickness
|
|
109
|
+
* @param hoverColor The color of the gizmo when hovering over and dragging
|
|
110
|
+
* @param disableColor The Color of the gizmo when its disabled
|
|
99
111
|
*/
|
|
100
|
-
constructor(dragAxis: Vector3, color?: Color3, gizmoLayer?: UtilityLayerRenderer, parent?: Nullable<ScaleGizmo>, thickness?: number);
|
|
112
|
+
constructor(dragAxis: Vector3, color?: Color3, gizmoLayer?: UtilityLayerRenderer, parent?: Nullable<ScaleGizmo>, thickness?: number, hoverColor?: Color3, disableColor?: Color3);
|
|
101
113
|
/**
|
|
102
114
|
* Create Geometry for Gizmo
|
|
103
115
|
* @param parentMesh
|
package/Gizmos/axisScaleGizmo.js
CHANGED
|
@@ -8,6 +8,7 @@ import { PointerDragBehavior } from "../Behaviors/Meshes/pointerDragBehavior.js"
|
|
|
8
8
|
import { Gizmo } from "./gizmo.js";
|
|
9
9
|
import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer.js";
|
|
10
10
|
import { Color3 } from "../Maths/math.color.js";
|
|
11
|
+
import { Epsilon } from "../Maths/math.constants.js";
|
|
11
12
|
/**
|
|
12
13
|
* Single axis scale gizmo
|
|
13
14
|
*/
|
|
@@ -31,8 +32,10 @@ export class AxisScaleGizmo extends Gizmo {
|
|
|
31
32
|
* @param gizmoLayer The utility layer the gizmo will be added to
|
|
32
33
|
* @param parent
|
|
33
34
|
* @param thickness display gizmo axis thickness
|
|
35
|
+
* @param hoverColor The color of the gizmo when hovering over and dragging
|
|
36
|
+
* @param disableColor The Color of the gizmo when its disabled
|
|
34
37
|
*/
|
|
35
|
-
constructor(dragAxis, color = Color3.Gray(), gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer, parent = null, thickness = 1) {
|
|
38
|
+
constructor(dragAxis, color = Color3.Gray(), gizmoLayer = UtilityLayerRenderer.DefaultUtilityLayer, parent = null, thickness = 1, hoverColor = Color3.Yellow(), disableColor = Color3.Gray()) {
|
|
36
39
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
37
40
|
super(gizmoLayer);
|
|
38
41
|
this._pointerObserver = null;
|
|
@@ -57,6 +60,10 @@ export class AxisScaleGizmo extends Gizmo {
|
|
|
57
60
|
* The magnitude of the drag strength (scaling factor)
|
|
58
61
|
*/
|
|
59
62
|
this.dragScale = 1;
|
|
63
|
+
/**
|
|
64
|
+
* Incremental snap scaling (default is false). When true, with a snapDistance of 0.1, scaling will be 1.1,1.2,1.3 instead of, when false: 1.1,1.21,1.33,...
|
|
65
|
+
*/
|
|
66
|
+
this.incrementalSnap = false;
|
|
60
67
|
this._isEnabled = true;
|
|
61
68
|
this._parent = null;
|
|
62
69
|
this._dragging = false;
|
|
@@ -67,9 +74,9 @@ export class AxisScaleGizmo extends Gizmo {
|
|
|
67
74
|
this._coloredMaterial.diffuseColor = color;
|
|
68
75
|
this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));
|
|
69
76
|
this._hoverMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
|
|
70
|
-
this._hoverMaterial.diffuseColor =
|
|
77
|
+
this._hoverMaterial.diffuseColor = hoverColor;
|
|
71
78
|
this._disableMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
|
|
72
|
-
this._disableMaterial.diffuseColor =
|
|
79
|
+
this._disableMaterial.diffuseColor = disableColor;
|
|
73
80
|
this._disableMaterial.alpha = 0.4;
|
|
74
81
|
// Build mesh + Collider
|
|
75
82
|
this._gizmoMesh = new Mesh("axis", gizmoLayer.utilityLayerScene);
|
|
@@ -102,6 +109,7 @@ export class AxisScaleGizmo extends Gizmo {
|
|
|
102
109
|
this.dragBehavior.updateDragPlane = false;
|
|
103
110
|
this._rootMesh.addBehavior(this.dragBehavior);
|
|
104
111
|
let currentSnapDragDistance = 0;
|
|
112
|
+
let currentSnapDragDistanceIncremental = 0;
|
|
105
113
|
const tmpSnapEvent = { snapDistance: 0 };
|
|
106
114
|
this.dragBehavior.onDragObservable.add((event) => {
|
|
107
115
|
if (this.attachedNode) {
|
|
@@ -122,9 +130,11 @@ export class AxisScaleGizmo extends Gizmo {
|
|
|
122
130
|
}
|
|
123
131
|
else {
|
|
124
132
|
currentSnapDragDistance += dragStrength;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
currentSnapDragDistanceIncremental += dragStrength;
|
|
134
|
+
const currentSnap = this.incrementalSnap ? currentSnapDragDistanceIncremental : currentSnapDragDistance;
|
|
135
|
+
if (Math.abs(currentSnap) > this.snapDistance) {
|
|
136
|
+
dragSteps = Math.floor(Math.abs(currentSnap) / this.snapDistance);
|
|
137
|
+
if (currentSnap < 0) {
|
|
128
138
|
dragSteps *= -1;
|
|
129
139
|
}
|
|
130
140
|
currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;
|
|
@@ -135,14 +145,29 @@ export class AxisScaleGizmo extends Gizmo {
|
|
|
135
145
|
tmpVector.scaleInPlace(0);
|
|
136
146
|
}
|
|
137
147
|
}
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
tmpVector.addInPlaceFromFloats(1, 1, 1);
|
|
149
|
+
// can't use Math.sign here because Math.sign(0) is 0 and it needs to be positive
|
|
150
|
+
tmpVector.x = Math.abs(tmpVector.x) < AxisScaleGizmo.MinimumAbsoluteScale ? AxisScaleGizmo.MinimumAbsoluteScale * (tmpVector.x < 0 ? -1 : 1) : tmpVector.x;
|
|
151
|
+
tmpVector.y = Math.abs(tmpVector.y) < AxisScaleGizmo.MinimumAbsoluteScale ? AxisScaleGizmo.MinimumAbsoluteScale * (tmpVector.y < 0 ? -1 : 1) : tmpVector.y;
|
|
152
|
+
tmpVector.z = Math.abs(tmpVector.z) < AxisScaleGizmo.MinimumAbsoluteScale ? AxisScaleGizmo.MinimumAbsoluteScale * (tmpVector.z < 0 ? -1 : 1) : tmpVector.z;
|
|
140
153
|
const transformNode = this.attachedNode._isMesh ? this.attachedNode : undefined;
|
|
154
|
+
if (Math.abs(this.snapDistance) > 0 && this.incrementalSnap) {
|
|
155
|
+
// get current scaling
|
|
156
|
+
this.attachedNode.getWorldMatrix().decompose(undefined, TmpVectors.Quaternion[0], TmpVectors.Vector3[2], Gizmo.PreserveScaling ? transformNode : undefined);
|
|
157
|
+
// apply incrementaly, without taking care of current scaling value
|
|
158
|
+
Matrix.ComposeToRef(tmpVector, TmpVectors.Quaternion[0], TmpVectors.Vector3[2], TmpVectors.Matrix[1]);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
Matrix.ScalingToRef(tmpVector.x, tmpVector.y, tmpVector.z, TmpVectors.Matrix[2]);
|
|
162
|
+
TmpVectors.Matrix[2].multiplyToRef(this.attachedNode.getWorldMatrix(), TmpVectors.Matrix[1]);
|
|
163
|
+
}
|
|
164
|
+
// check scaling are not out of bounds. If not, copy resulting temp matrix to node world matrix
|
|
141
165
|
TmpVectors.Matrix[1].decompose(TmpVectors.Vector3[1], undefined, undefined, Gizmo.PreserveScaling ? transformNode : undefined);
|
|
142
166
|
const maxScale = 100000;
|
|
143
167
|
if (Math.abs(TmpVectors.Vector3[1].x) < maxScale && Math.abs(TmpVectors.Vector3[1].y) < maxScale && Math.abs(TmpVectors.Vector3[1].z) < maxScale) {
|
|
144
168
|
this.attachedNode.getWorldMatrix().copyFrom(TmpVectors.Matrix[1]);
|
|
145
169
|
}
|
|
170
|
+
// notify observers
|
|
146
171
|
if (snapped) {
|
|
147
172
|
tmpSnapEvent.snapDistance = this.snapDistance * dragSteps;
|
|
148
173
|
this.onSnapObservable.notifyObservers(tmpSnapEvent);
|
|
@@ -270,4 +295,8 @@ export class AxisScaleGizmo extends Gizmo {
|
|
|
270
295
|
}
|
|
271
296
|
}
|
|
272
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* The minimal absolute scale per component. can be positive or negative but never smaller.
|
|
300
|
+
*/
|
|
301
|
+
AxisScaleGizmo.MinimumAbsoluteScale = Epsilon;
|
|
273
302
|
//# sourceMappingURL=axisScaleGizmo.js.map
|