@babylonjs/core 6.17.0 → 6.18.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.
Files changed (86) hide show
  1. package/Audio/audioEngine.d.ts +1 -1
  2. package/Audio/audioEngine.js +24 -13
  3. package/Audio/audioEngine.js.map +1 -1
  4. package/Bones/skeleton.d.ts +3 -1
  5. package/Bones/skeleton.js +11 -2
  6. package/Bones/skeleton.js.map +1 -1
  7. package/DeviceInput/webDeviceInputSystem.js +26 -1
  8. package/DeviceInput/webDeviceInputSystem.js.map +1 -1
  9. package/Engines/thinEngine.js +2 -2
  10. package/Engines/thinEngine.js.map +1 -1
  11. package/Materials/Node/Blocks/Teleport/teleportInBlock.js +1 -0
  12. package/Materials/Node/Blocks/Teleport/teleportInBlock.js.map +1 -1
  13. package/Materials/greasedLinePluginMaterial.d.ts +7 -2
  14. package/Materials/greasedLinePluginMaterial.js +46 -21
  15. package/Materials/greasedLinePluginMaterial.js.map +1 -1
  16. package/Meshes/Node/Blocks/Instances/instantiateBlock.d.ts +77 -0
  17. package/Meshes/Node/Blocks/Instances/instantiateBlock.js +169 -0
  18. package/Meshes/Node/Blocks/Instances/instantiateBlock.js.map +1 -0
  19. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.d.ts +6 -0
  20. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js +74 -68
  21. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js.map +1 -1
  22. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.d.ts +11 -0
  23. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js +94 -66
  24. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js.map +1 -1
  25. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.d.ts +6 -0
  26. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js +68 -62
  27. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js.map +1 -1
  28. package/Meshes/Node/Blocks/Set/setColorsBlock.d.ts +5 -0
  29. package/Meshes/Node/Blocks/Set/setColorsBlock.js +7 -0
  30. package/Meshes/Node/Blocks/Set/setColorsBlock.js.map +1 -1
  31. package/Meshes/Node/Blocks/Set/setNormalsBlock.d.ts +5 -0
  32. package/Meshes/Node/Blocks/Set/setNormalsBlock.js +7 -0
  33. package/Meshes/Node/Blocks/Set/setNormalsBlock.js.map +1 -1
  34. package/Meshes/Node/Blocks/Set/setPositionsBlock.d.ts +5 -0
  35. package/Meshes/Node/Blocks/Set/setPositionsBlock.js +7 -0
  36. package/Meshes/Node/Blocks/Set/setPositionsBlock.js.map +1 -1
  37. package/Meshes/Node/Blocks/Set/setTangentsBlock.d.ts +5 -0
  38. package/Meshes/Node/Blocks/Set/setTangentsBlock.js +7 -0
  39. package/Meshes/Node/Blocks/Set/setTangentsBlock.js.map +1 -1
  40. package/Meshes/Node/Blocks/Set/setUVsBlock.d.ts +5 -0
  41. package/Meshes/Node/Blocks/Set/setUVsBlock.js +7 -0
  42. package/Meshes/Node/Blocks/Set/setUVsBlock.js.map +1 -1
  43. package/Meshes/Node/Blocks/Sources/meshBlock.d.ts +4 -0
  44. package/Meshes/Node/Blocks/Sources/meshBlock.js +6 -0
  45. package/Meshes/Node/Blocks/Sources/meshBlock.js.map +1 -1
  46. package/Meshes/Node/Blocks/Teleport/teleportInBlock.js +1 -0
  47. package/Meshes/Node/Blocks/Teleport/teleportInBlock.js.map +1 -1
  48. package/Meshes/Node/Blocks/computeNormalsBlock.js +3 -0
  49. package/Meshes/Node/Blocks/computeNormalsBlock.js.map +1 -1
  50. package/Meshes/Node/Blocks/geometryCollectionBlock.d.ts +76 -0
  51. package/Meshes/Node/Blocks/geometryCollectionBlock.js +163 -0
  52. package/Meshes/Node/Blocks/geometryCollectionBlock.js.map +1 -0
  53. package/Meshes/Node/Blocks/geometryInfoBlock.d.ts +43 -0
  54. package/Meshes/Node/Blocks/geometryInfoBlock.js +100 -0
  55. package/Meshes/Node/Blocks/geometryInfoBlock.js.map +1 -0
  56. package/Meshes/Node/Blocks/geometryInputBlock.js +2 -0
  57. package/Meshes/Node/Blocks/geometryInputBlock.js.map +1 -1
  58. package/Meshes/Node/Enums/nodeGeometryContextualSources.d.ts +5 -1
  59. package/Meshes/Node/Enums/nodeGeometryContextualSources.js +4 -0
  60. package/Meshes/Node/Enums/nodeGeometryContextualSources.js.map +1 -1
  61. package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.d.ts +5 -0
  62. package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.js.map +1 -1
  63. package/Meshes/Node/index.d.ts +3 -0
  64. package/Meshes/Node/index.js +3 -0
  65. package/Meshes/Node/index.js.map +1 -1
  66. package/Meshes/Node/nodeGeometry.d.ts +7 -0
  67. package/Meshes/Node/nodeGeometry.js +17 -0
  68. package/Meshes/Node/nodeGeometry.js.map +1 -1
  69. package/Meshes/Node/nodeGeometryBlock.d.ts +8 -3
  70. package/Meshes/Node/nodeGeometryBlock.js +24 -5
  71. package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
  72. package/Meshes/Node/nodeGeometryBuildState.d.ts +3 -1
  73. package/Meshes/Node/nodeGeometryBuildState.js +34 -12
  74. package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
  75. package/Meshes/mesh.vertexData.d.ts +4 -0
  76. package/Meshes/mesh.vertexData.js +4 -0
  77. package/Meshes/mesh.vertexData.js.map +1 -1
  78. package/Meshes/transformNode.js +7 -3
  79. package/Meshes/transformNode.js.map +1 -1
  80. package/Shaders/gpuRenderParticles.vertex.js +5 -5
  81. package/Shaders/gpuRenderParticles.vertex.js.map +1 -1
  82. package/Shaders/particles.vertex.js +5 -5
  83. package/Shaders/particles.vertex.js.map +1 -1
  84. package/Sprites/sprite.js +4 -4
  85. package/Sprites/sprite.js.map +1 -1
  86. package/package.json +1 -1
@@ -0,0 +1,169 @@
1
+ import { __decorate } from "../../../../tslib.es6.js";
2
+ import { NodeGeometryBlock } from "../../nodeGeometryBlock.js";
3
+ import { RegisterClass } from "../../../../Misc/typeStore.js";
4
+ import { NodeGeometryBlockConnectionPointTypes } from "../../Enums/nodeGeometryConnectionPointTypes.js";
5
+ import { Vector3 } from "../../../../Maths/math.vector.js";
6
+ import { PropertyTypeForEdition, editableInPropertyPage } from "../../../../Decorators/nodeDecorator.js";
7
+ /**
8
+ * Block used to instantiate a geometry inside a loop
9
+ */
10
+ export class InstantiateBlock extends NodeGeometryBlock {
11
+ /**
12
+ * Create a new InstantiateBlock
13
+ * @param name defines the block name
14
+ */
15
+ constructor(name) {
16
+ super(name);
17
+ /**
18
+ * Gets or sets a boolean indicating that this block can evaluate context
19
+ * Build performance is improved when this value is set to false as the system will cache values instead of reevaluating everything per context change
20
+ */
21
+ this.evaluateContext = true;
22
+ this.registerInput("instance", NodeGeometryBlockConnectionPointTypes.Geometry, true);
23
+ this.registerInput("count", NodeGeometryBlockConnectionPointTypes.Int, true, 1);
24
+ this.registerInput("position", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.Zero());
25
+ this.registerInput("rotation", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.Zero());
26
+ this.registerInput("scaling", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.One());
27
+ this.registerInput("matrix", NodeGeometryBlockConnectionPointTypes.Matrix, true);
28
+ this.scaling.acceptedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Float);
29
+ this.registerOutput("output", NodeGeometryBlockConnectionPointTypes.Geometry);
30
+ }
31
+ /**
32
+ * Gets the current index in the current flow
33
+ * @returns the current index
34
+ */
35
+ getExecutionIndex() {
36
+ return this._currentIndex;
37
+ }
38
+ /**
39
+ * Gets the current loop index in the current flow
40
+ * @returns the current loop index
41
+ */
42
+ getExecutionLoopIndex() {
43
+ return this._currentIndex;
44
+ }
45
+ /**
46
+ * Gets the current face index in the current flow
47
+ * @returns the current face index
48
+ */
49
+ getExecutionFaceIndex() {
50
+ return 0;
51
+ }
52
+ /**
53
+ * Gets the current class name
54
+ * @returns the class name
55
+ */
56
+ getClassName() {
57
+ return "InstantiateBlock";
58
+ }
59
+ /**
60
+ * Gets the instance input component
61
+ */
62
+ get instance() {
63
+ return this._inputs[0];
64
+ }
65
+ /**
66
+ * Gets the instance input component
67
+ */
68
+ get count() {
69
+ return this._inputs[1];
70
+ }
71
+ /**
72
+ * Gets the position input component
73
+ */
74
+ get position() {
75
+ return this._inputs[2];
76
+ }
77
+ /**
78
+ * Gets the rotation input component
79
+ */
80
+ get rotation() {
81
+ return this._inputs[3];
82
+ }
83
+ /**
84
+ * Gets the scaling input component
85
+ */
86
+ get scaling() {
87
+ return this._inputs[4];
88
+ }
89
+ /**
90
+ * Gets the matrix input component
91
+ */
92
+ get matrix() {
93
+ return this._inputs[5];
94
+ }
95
+ /**
96
+ * Gets the geometry output component
97
+ */
98
+ get output() {
99
+ return this._outputs[0];
100
+ }
101
+ _buildBlock(state) {
102
+ const func = (state) => {
103
+ state.executionContext = this;
104
+ // Processing
105
+ const iterationCount = this.count.getConnectedValue(state);
106
+ const additionalVertexData = [];
107
+ for (this._currentIndex = 0; this._currentIndex < iterationCount; this._currentIndex++) {
108
+ const instanceGeometry = this.instance.getConnectedValue(state);
109
+ if (!instanceGeometry || !instanceGeometry.positions || instanceGeometry.positions.length === 0) {
110
+ continue;
111
+ }
112
+ // Clone the instance
113
+ const clone = instanceGeometry.clone();
114
+ // Transform
115
+ if (this.matrix.isConnected) {
116
+ const transform = this.matrix.getConnectedValue(state);
117
+ state._instantiateWithMatrix(clone, transform, additionalVertexData);
118
+ }
119
+ else {
120
+ const position = this.position.getConnectedValue(state) || Vector3.ZeroReadOnly;
121
+ const scaling = state.adaptInput(this.scaling, NodeGeometryBlockConnectionPointTypes.Vector3, Vector3.OneReadOnly);
122
+ const rotation = this.rotation.getConnectedValue(state) || Vector3.ZeroReadOnly;
123
+ state._instantiate(clone, position, rotation, scaling, additionalVertexData);
124
+ }
125
+ }
126
+ // Merge
127
+ if (additionalVertexData.length) {
128
+ if (additionalVertexData.length === 1) {
129
+ this._vertexData = additionalVertexData[0];
130
+ }
131
+ else {
132
+ // We do not merge the main one as user can use a merge node if wanted
133
+ const main = additionalVertexData.splice(0, 1)[0];
134
+ this._vertexData = main.merge(additionalVertexData, true, false, true, true);
135
+ }
136
+ }
137
+ return this._vertexData;
138
+ };
139
+ // Storage
140
+ if (this.evaluateContext) {
141
+ this.output._storedFunction = func;
142
+ }
143
+ else {
144
+ this.output._storedValue = func(state);
145
+ }
146
+ }
147
+ _dumpPropertiesCode() {
148
+ const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.evaluateContext = ${this.evaluateContext ? "true" : "false"};\n`;
149
+ return codeString;
150
+ }
151
+ /**
152
+ * Serializes this block in a JSON representation
153
+ * @returns the serialized block object
154
+ */
155
+ serialize() {
156
+ const serializationObject = super.serialize();
157
+ serializationObject.evaluateContext = this.evaluateContext;
158
+ return serializationObject;
159
+ }
160
+ _deserialize(serializationObject) {
161
+ super._deserialize(serializationObject);
162
+ this.evaluateContext = serializationObject.evaluateContext;
163
+ }
164
+ }
165
+ __decorate([
166
+ editableInPropertyPage("Evaluate context", PropertyTypeForEdition.Boolean, "ADVANCED", { notifiers: { rebuild: true } })
167
+ ], InstantiateBlock.prototype, "evaluateContext", void 0);
168
+ RegisterClass("BABYLON.InstantiateBlock", InstantiateBlock);
169
+ //# sourceMappingURL=instantiateBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instantiateBlock.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Meshes/Node/Blocks/Instances/instantiateBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,qCAAqC,EAAE,MAAM,8CAA8C,CAAC;AAIrG,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAA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AAC,oBAAoB,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;iBAChF;aACJ;YACD,OAAO,IAAI,CAAC,WAAW,CAAC;QAC5B,CAAC,CAAC;QAEF,UAAU;QAEV,IAAI,IAAI,CAAC,eAAe,EAAE;YACtB,IAAI,CAAC,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC;SACtC;aAAM;YACH,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1C;IACL,CAAC;IAES,mBAAmB;QACzB,MAAM,UAAU,GAAG,KAAK,CAAC,mBAAmB,EAAE,GAAG,GAAG,IAAI,CAAC,iBAAiB,sBAAsB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC;QAC7I,OAAO,UAAU,CAAC;IACtB,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,MAAM,mBAAmB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAE9C,mBAAmB,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAE3D,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEM,YAAY,CAAC,mBAAwB;QACxC,KAAK,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;QAExC,IAAI,CAAC,eAAe,GAAG,mBAAmB,CAAC,eAAe,CAAC;IAC/D,CAAC;CACJ;AA/KU;IADN,sBAAsB,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;yDAC3F;AAiLlC,aAAa,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC","sourcesContent":["import { NodeGeometryBlock } from \"../../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../../nodeGeometryBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { NodeGeometryBuildState } from \"../../nodeGeometryBuildState\";\r\nimport type { INodeGeometryExecutionContext } from \"../../Interfaces/nodeGeometryExecutionContext\";\r\nimport type { VertexData } from \"../../../mesh.vertexData\";\r\nimport { Vector3 } from \"../../../../Maths/math.vector\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"core/Decorators/nodeDecorator\";\r\n\r\n/**\r\n * Block used to instantiate a geometry inside a loop\r\n */\r\nexport class InstantiateBlock extends NodeGeometryBlock implements INodeGeometryExecutionContext {\r\n private _vertexData: VertexData;\r\n private _currentIndex: number;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this block can evaluate context\r\n * Build performance is improved when this value is set to false as the system will cache values instead of reevaluating everything per context change\r\n */\r\n @editableInPropertyPage(\"Evaluate context\", PropertyTypeForEdition.Boolean, \"ADVANCED\", { notifiers: { rebuild: true } })\r\n public evaluateContext = true;\r\n\r\n /**\r\n * Create a new InstantiateBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"instance\", NodeGeometryBlockConnectionPointTypes.Geometry, true);\r\n this.registerInput(\"count\", NodeGeometryBlockConnectionPointTypes.Int, true, 1);\r\n this.registerInput(\"position\", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.Zero());\r\n this.registerInput(\"rotation\", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.Zero());\r\n this.registerInput(\"scaling\", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.One());\r\n this.registerInput(\"matrix\", NodeGeometryBlockConnectionPointTypes.Matrix, true);\r\n\r\n this.scaling.acceptedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.Geometry);\r\n }\r\n\r\n /**\r\n * Gets the current index in the current flow\r\n * @returns the current index\r\n */\r\n public getExecutionIndex(): number {\r\n return this._currentIndex;\r\n }\r\n\r\n /**\r\n * Gets the current loop index in the current flow\r\n * @returns the current loop index\r\n */\r\n public getExecutionLoopIndex(): number {\r\n return this._currentIndex;\r\n }\r\n\r\n /**\r\n * Gets the current face index in the current flow\r\n * @returns the current face index\r\n */\r\n public getExecutionFaceIndex(): number {\r\n return 0;\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"InstantiateBlock\";\r\n }\r\n\r\n /**\r\n * Gets the instance input component\r\n */\r\n public get instance(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the instance input component\r\n */\r\n public get count(): NodeGeometryConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the position input component\r\n */\r\n public get position(): NodeGeometryConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the rotation input component\r\n */\r\n public get rotation(): NodeGeometryConnectionPoint {\r\n return this._inputs[3];\r\n }\r\n\r\n /**\r\n * Gets the scaling input component\r\n */\r\n public get scaling(): NodeGeometryConnectionPoint {\r\n return this._inputs[4];\r\n }\r\n\r\n /**\r\n * Gets the matrix input component\r\n */\r\n public get matrix(): NodeGeometryConnectionPoint {\r\n return this._inputs[5];\r\n }\r\n\r\n /**\r\n * Gets the geometry output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock(state: NodeGeometryBuildState) {\r\n const func = (state: NodeGeometryBuildState) => {\r\n state.executionContext = this;\r\n\r\n // Processing\r\n const iterationCount = this.count.getConnectedValue(state);\r\n const additionalVertexData: VertexData[] = [];\r\n\r\n for (this._currentIndex = 0; this._currentIndex < iterationCount; this._currentIndex++) {\r\n const instanceGeometry = this.instance.getConnectedValue(state) as VertexData;\r\n\r\n if (!instanceGeometry || !instanceGeometry.positions || instanceGeometry.positions.length === 0) {\r\n continue;\r\n }\r\n\r\n // Clone the instance\r\n const clone = instanceGeometry.clone();\r\n\r\n // Transform\r\n if (this.matrix.isConnected) {\r\n const transform = this.matrix.getConnectedValue(state);\r\n state._instantiateWithMatrix(clone, transform, additionalVertexData);\r\n } else {\r\n const position = this.position.getConnectedValue(state) || Vector3.ZeroReadOnly;\r\n const scaling = state.adaptInput(this.scaling, NodeGeometryBlockConnectionPointTypes.Vector3, Vector3.OneReadOnly);\r\n const rotation = this.rotation.getConnectedValue(state) || Vector3.ZeroReadOnly;\r\n state._instantiate(clone, position, rotation, scaling, additionalVertexData);\r\n }\r\n }\r\n\r\n // Merge\r\n if (additionalVertexData.length) {\r\n if (additionalVertexData.length === 1) {\r\n this._vertexData = additionalVertexData[0];\r\n } else {\r\n // We do not merge the main one as user can use a merge node if wanted\r\n const main = additionalVertexData.splice(0, 1)[0];\r\n this._vertexData = main.merge(additionalVertexData, true, false, true, true);\r\n }\r\n }\r\n return this._vertexData;\r\n };\r\n\r\n // Storage\r\n\r\n if (this.evaluateContext) {\r\n this.output._storedFunction = func;\r\n } else {\r\n this.output._storedValue = func(state);\r\n }\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.evaluateContext = ${this.evaluateContext ? \"true\" : \"false\"};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.evaluateContext = this.evaluateContext;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.evaluateContext = serializationObject.evaluateContext;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.InstantiateBlock\", InstantiateBlock);\r\n"]}
@@ -9,6 +9,7 @@ import { Vector3 } from "../../../../Maths/math.vector";
9
9
  export declare class InstantiateOnFacesBlock extends NodeGeometryBlock implements INodeGeometryExecutionContext {
10
10
  private _vertexData;
11
11
  private _currentFaceIndex;
12
+ private _currentLoopIndex;
12
13
  private _currentPosition;
13
14
  private _vertex0;
14
15
  private _vertex1;
@@ -35,6 +36,11 @@ export declare class InstantiateOnFacesBlock extends NodeGeometryBlock implement
35
36
  * @returns the current face index
36
37
  */
37
38
  getExecutionFaceIndex(): number;
39
+ /**
40
+ * Gets the current loop index in the current flow
41
+ * @returns the current loop index
42
+ */
43
+ getExecutionLoopIndex(): number;
38
44
  /**
39
45
  * Gets the value associated with a contextual positions
40
46
  * @returns the value associated with the source
@@ -47,6 +47,13 @@ export class InstantiateOnFacesBlock extends NodeGeometryBlock {
47
47
  getExecutionFaceIndex() {
48
48
  return this._currentFaceIndex;
49
49
  }
50
+ /**
51
+ * Gets the current loop index in the current flow
52
+ * @returns the current loop index
53
+ */
54
+ getExecutionLoopIndex() {
55
+ return this._currentLoopIndex;
56
+ }
50
57
  /**
51
58
  * Gets the value associated with a contextual positions
52
59
  * @returns the value associated with the source
@@ -109,87 +116,84 @@ export class InstantiateOnFacesBlock extends NodeGeometryBlock {
109
116
  return this._outputs[0];
110
117
  }
111
118
  _buildBlock(state) {
112
- state.executionContext = this;
113
- this._vertexData = this.geometry.getConnectedValue(state);
114
- state.geometryContext = this._vertexData;
115
- if (!this._vertexData || !this._vertexData.positions || !this._vertexData.indices || !this.instance.isConnected) {
116
- state.executionContext = null;
117
- state.geometryContext = null;
118
- this.output._storedValue = null;
119
- return;
120
- }
121
- // Processing
122
- let instanceGeometry = null;
123
- if (!this.evaluateContext) {
124
- instanceGeometry = this.instance.getConnectedValue(state);
125
- if (!instanceGeometry || !instanceGeometry.positions || instanceGeometry.positions.length === 0) {
119
+ const func = (state) => {
120
+ state.executionContext = this;
121
+ this._vertexData = this.geometry.getConnectedValue(state);
122
+ state.geometryContext = this._vertexData;
123
+ if (!this._vertexData || !this._vertexData.positions || !this._vertexData.indices || !this.instance.isConnected) {
126
124
  state.executionContext = null;
127
125
  state.geometryContext = null;
128
126
  this.output._storedValue = null;
129
127
  return;
130
128
  }
131
- }
132
- const instanceCount = this.count.getConnectedValue(state);
133
- const faceCount = this._vertexData.indices.length / 3;
134
- const instancePerFace = instanceCount / faceCount;
135
- let accumulatedCount = 0;
136
- const additionalVertexData = [];
137
- let totalDone = 0;
138
- for (this._currentFaceIndex = 0; this._currentFaceIndex < faceCount; this._currentFaceIndex++) {
139
- // Extract face vertices
140
- this._vertex0.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3] * 3);
141
- this._vertex1.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 1] * 3);
142
- this._vertex2.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 2] * 3);
143
- accumulatedCount += instancePerFace;
144
- const countPerFace = (accumulatedCount | 0) - totalDone;
145
- if (countPerFace < 1) {
146
- continue;
147
- }
148
- for (let faceDispatchCount = 0; faceDispatchCount < countPerFace; faceDispatchCount++) {
149
- if (totalDone >= instanceCount) {
150
- break;
151
- }
152
- // Get random point on face
153
- let x = Math.random();
154
- let y = Math.random();
155
- if (x > y) {
156
- const temp = x;
157
- x = y;
158
- y = temp;
129
+ // Processing
130
+ let instanceGeometry = null;
131
+ const instanceCount = this.count.getConnectedValue(state);
132
+ const faceCount = this._vertexData.indices.length / 3;
133
+ const instancePerFace = instanceCount / faceCount;
134
+ let accumulatedCount = 0;
135
+ const additionalVertexData = [];
136
+ let totalDone = 0;
137
+ this._currentLoopIndex = 0;
138
+ for (this._currentFaceIndex = 0; this._currentFaceIndex < faceCount; this._currentFaceIndex++) {
139
+ // Extract face vertices
140
+ this._vertex0.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3] * 3);
141
+ this._vertex1.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 1] * 3);
142
+ this._vertex2.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 2] * 3);
143
+ accumulatedCount += instancePerFace;
144
+ const countPerFace = (accumulatedCount | 0) - totalDone;
145
+ if (countPerFace < 1) {
146
+ continue;
159
147
  }
160
- const s = x;
161
- const t = y - x;
162
- const u = 1 - s - t;
163
- this._currentPosition.set(s * this._vertex0.x + t * this._vertex1.x + u * this._vertex2.x, s * this._vertex0.y + t * this._vertex1.y + u * this._vertex2.y, s * this._vertex0.z + t * this._vertex1.z + u * this._vertex2.z);
164
- // Clone the instance
165
- if (this.evaluateContext) {
148
+ for (let faceDispatchCount = 0; faceDispatchCount < countPerFace; faceDispatchCount++) {
149
+ if (totalDone >= instanceCount) {
150
+ break;
151
+ }
152
+ // Get random point on face
153
+ let x = Math.random();
154
+ let y = Math.random();
155
+ if (x > y) {
156
+ const temp = x;
157
+ x = y;
158
+ y = temp;
159
+ }
160
+ const s = x;
161
+ const t = y - x;
162
+ const u = 1 - s - t;
163
+ this._currentPosition.set(s * this._vertex0.x + t * this._vertex1.x + u * this._vertex2.x, s * this._vertex0.y + t * this._vertex1.y + u * this._vertex2.y, s * this._vertex0.z + t * this._vertex1.z + u * this._vertex2.z);
164
+ // Clone the instance
166
165
  instanceGeometry = this.instance.getConnectedValue(state);
167
166
  if (!instanceGeometry || !instanceGeometry.positions || instanceGeometry.positions.length === 0) {
168
167
  continue;
169
168
  }
169
+ const clone = instanceGeometry.clone();
170
+ const scaling = state.adaptInput(this.scaling, NodeGeometryBlockConnectionPointTypes.Vector3, Vector3.OneReadOnly);
171
+ const rotation = this.rotation.getConnectedValue(state) || Vector3.ZeroReadOnly;
172
+ state._instantiate(clone, this._currentPosition, rotation, scaling, additionalVertexData);
173
+ totalDone++;
174
+ this._currentLoopIndex++;
170
175
  }
171
- const clone = instanceGeometry.clone();
172
- const scaling = state.adaptInput(this.scaling, NodeGeometryBlockConnectionPointTypes.Vector3, Vector3.OneReadOnly);
173
- const rotation = this.rotation.getConnectedValue(state) || Vector3.ZeroReadOnly;
174
- state._instantiate(clone, this._currentPosition, rotation, scaling, additionalVertexData);
175
- totalDone++;
176
176
  }
177
- }
178
- // Merge
179
- if (additionalVertexData.length) {
180
- if (additionalVertexData.length === 1) {
181
- this._vertexData = additionalVertexData[0];
182
- }
183
- else {
184
- // We do not merge the main one as user can use a merge node if wanted
185
- const main = additionalVertexData.splice(0, 1)[0];
186
- this._vertexData = main.merge(additionalVertexData, true, false, true, true);
177
+ // Merge
178
+ if (additionalVertexData.length) {
179
+ if (additionalVertexData.length === 1) {
180
+ this._vertexData = additionalVertexData[0];
181
+ }
182
+ else {
183
+ // We do not merge the main one as user can use a merge node if wanted
184
+ const main = additionalVertexData.splice(0, 1)[0];
185
+ this._vertexData = main.merge(additionalVertexData, true, false, true, true);
186
+ }
187
187
  }
188
- }
188
+ return this._vertexData;
189
+ };
189
190
  // Storage
190
- this.output._storedValue = this._vertexData;
191
- state.executionContext = null;
192
- state.geometryContext = null;
191
+ if (this.evaluateContext) {
192
+ this.output._storedFunction = func;
193
+ }
194
+ else {
195
+ this.output._storedValue = func(state);
196
+ }
193
197
  }
194
198
  _dumpPropertiesCode() {
195
199
  const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.evaluateContext = ${this.evaluateContext ? "true" : "false"};\n`;
@@ -206,7 +210,9 @@ export class InstantiateOnFacesBlock extends NodeGeometryBlock {
206
210
  }
207
211
  _deserialize(serializationObject) {
208
212
  super._deserialize(serializationObject);
209
- this.evaluateContext = serializationObject.evaluateContext;
213
+ if (serializationObject.evaluateContext !== undefined) {
214
+ this.evaluateContext = serializationObject.evaluateContext;
215
+ }
210
216
  }
211
217
  }
212
218
  __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"instantiateOnFacesBlock.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC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,SAAS;QACZ,MAAM,mBAAmB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAE9C,mBAAmB,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAE3D,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEM,YAAY,CAAC,mBAAwB;QACxC,KAAK,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;QAExC,IAAI,CAAC,eAAe,GAAG,mBAAmB,CAAC,eAAe,CAAC;IAC/D,CAAC;CACJ;AAvOU;IADN,sBAAsB,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;gEAC3F;AAyOlC,aAAa,CAAC,iCAAiC,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { NodeGeometryBlock } from \"../../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../../nodeGeometryBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { NodeGeometryBuildState } from \"../../nodeGeometryBuildState\";\r\nimport type { INodeGeometryExecutionContext } from \"../../Interfaces/nodeGeometryExecutionContext\";\r\nimport type { VertexData } from \"../../../mesh.vertexData\";\r\nimport { Vector3 } from \"../../../../Maths/math.vector\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"../../../../Decorators/nodeDecorator\";\r\nimport type { Nullable } from \"../../../../types\";\r\n\r\n/**\r\n * Block used to instance geometry on every face of a geometry\r\n */\r\nexport class InstantiateOnFacesBlock extends NodeGeometryBlock implements INodeGeometryExecutionContext {\r\n private _vertexData: VertexData;\r\n private _currentFaceIndex: number;\r\n private _currentPosition = new Vector3();\r\n private _vertex0 = new Vector3();\r\n private _vertex1 = new Vector3();\r\n private _vertex2 = new Vector3();\r\n private _tempVector0 = new Vector3();\r\n private _tempVector1 = new Vector3();\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this block can evaluate context\r\n * Build performance is improved when this value is set to false as the system will cache values instead of reevaluating everything per context change\r\n */\r\n @editableInPropertyPage(\"Evaluate context\", PropertyTypeForEdition.Boolean, \"ADVANCED\", { notifiers: { rebuild: true } })\r\n public evaluateContext = true;\r\n\r\n /**\r\n * Create a new InstantiateOnFacesBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"geometry\", NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this.registerInput(\"instance\", NodeGeometryBlockConnectionPointTypes.Geometry, true);\r\n this.registerInput(\"rotation\", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.Zero());\r\n this.registerInput(\"scaling\", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.One());\r\n this.registerInput(\"count\", NodeGeometryBlockConnectionPointTypes.Int, true, 256);\r\n\r\n this.scaling.acceptedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.Geometry);\r\n }\r\n\r\n /**\r\n * Gets the current index in the current flow\r\n * @returns the current index\r\n */\r\n public getExecutionIndex(): number {\r\n return 0;\r\n }\r\n\r\n /**\r\n * Gets the current face index in the current flow\r\n * @returns the current face index\r\n */\r\n public getExecutionFaceIndex(): number {\r\n return this._currentFaceIndex;\r\n }\r\n\r\n /**\r\n * Gets the value associated with a contextual positions\r\n * @returns the value associated with the source\r\n */\r\n public getOverridePositionsContextualValue() {\r\n return this._currentPosition;\r\n }\r\n\r\n /**\r\n * Gets the value associated with a contextual normals\r\n * @returns the value associated with the source\r\n */\r\n public getOverrideNormalsContextualValue() {\r\n this._vertex1.subtractToRef(this._vertex0, this._tempVector0);\r\n this._vertex2.subtractToRef(this._vertex1, this._tempVector1);\r\n this._tempVector0.normalize();\r\n this._tempVector1.normalize();\r\n return Vector3.Cross(this._tempVector1, this._tempVector0);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"InstantiateOnFacesBlock\";\r\n }\r\n\r\n /**\r\n * Gets the geometry input component\r\n */\r\n public get geometry(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the instance input component\r\n */\r\n public get instance(): NodeGeometryConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the rotation input component\r\n */\r\n public get rotation(): NodeGeometryConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the scaling input component\r\n */\r\n public get scaling(): NodeGeometryConnectionPoint {\r\n return this._inputs[3];\r\n }\r\n\r\n /**\r\n * Gets the count input component\r\n */\r\n public get count(): NodeGeometryConnectionPoint {\r\n return this._inputs[4];\r\n }\r\n\r\n /**\r\n * Gets the geometry output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock(state: NodeGeometryBuildState) {\r\n state.executionContext = this;\r\n\r\n this._vertexData = this.geometry.getConnectedValue(state);\r\n state.geometryContext = this._vertexData;\r\n\r\n if (!this._vertexData || !this._vertexData.positions || !this._vertexData.indices || !this.instance.isConnected) {\r\n state.executionContext = null;\r\n state.geometryContext = null;\r\n this.output._storedValue = null;\r\n return;\r\n }\r\n\r\n // Processing\r\n let instanceGeometry: Nullable<VertexData> = null;\r\n if (!this.evaluateContext) {\r\n instanceGeometry = this.instance.getConnectedValue(state) as VertexData;\r\n\r\n if (!instanceGeometry || !instanceGeometry.positions || instanceGeometry.positions.length === 0) {\r\n state.executionContext = null;\r\n state.geometryContext = null;\r\n this.output._storedValue = null;\r\n return;\r\n }\r\n }\r\n\r\n const instanceCount = this.count.getConnectedValue(state);\r\n const faceCount = this._vertexData.indices.length / 3;\r\n const instancePerFace = instanceCount / faceCount;\r\n let accumulatedCount = 0;\r\n const additionalVertexData: VertexData[] = [];\r\n let totalDone = 0;\r\n\r\n for (this._currentFaceIndex = 0; this._currentFaceIndex < faceCount; this._currentFaceIndex++) {\r\n // Extract face vertices\r\n this._vertex0.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3] * 3);\r\n this._vertex1.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 1] * 3);\r\n this._vertex2.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 2] * 3);\r\n\r\n accumulatedCount += instancePerFace;\r\n const countPerFace = (accumulatedCount | 0) - totalDone;\r\n\r\n if (countPerFace < 1) {\r\n continue;\r\n }\r\n\r\n for (let faceDispatchCount = 0; faceDispatchCount < countPerFace; faceDispatchCount++) {\r\n if (totalDone >= instanceCount) {\r\n break;\r\n }\r\n\r\n // Get random point on face\r\n let x = Math.random();\r\n let y = Math.random();\r\n\r\n if (x > y) {\r\n const temp = x;\r\n x = y;\r\n y = temp;\r\n }\r\n const s = x;\r\n const t = y - x;\r\n const u = 1 - s - t;\r\n\r\n this._currentPosition.set(\r\n s * this._vertex0.x + t * this._vertex1.x + u * this._vertex2.x,\r\n s * this._vertex0.y + t * this._vertex1.y + u * this._vertex2.y,\r\n s * this._vertex0.z + t * this._vertex1.z + u * this._vertex2.z\r\n );\r\n\r\n // Clone the instance\r\n if (this.evaluateContext) {\r\n instanceGeometry = this.instance.getConnectedValue(state) as VertexData;\r\n\r\n if (!instanceGeometry || !instanceGeometry.positions || instanceGeometry.positions.length === 0) {\r\n continue;\r\n }\r\n }\r\n const clone = instanceGeometry!.clone();\r\n\r\n const scaling = state.adaptInput(this.scaling, NodeGeometryBlockConnectionPointTypes.Vector3, Vector3.OneReadOnly);\r\n const rotation = this.rotation.getConnectedValue(state) || Vector3.ZeroReadOnly;\r\n state._instantiate(clone, this._currentPosition, rotation, scaling, additionalVertexData);\r\n totalDone++;\r\n }\r\n }\r\n\r\n // Merge\r\n if (additionalVertexData.length) {\r\n if (additionalVertexData.length === 1) {\r\n this._vertexData = additionalVertexData[0];\r\n } else {\r\n // We do not merge the main one as user can use a merge node if wanted\r\n const main = additionalVertexData.splice(0, 1)[0];\r\n this._vertexData = main.merge(additionalVertexData, true, false, true, true);\r\n }\r\n }\r\n\r\n // Storage\r\n this.output._storedValue = this._vertexData;\r\n state.executionContext = null;\r\n state.geometryContext = null;\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.evaluateContext = ${this.evaluateContext ? \"true\" : \"false\"};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.evaluateContext = this.evaluateContext;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.evaluateContext = serializationObject.evaluateContext;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.InstantiateOnFacesBlock\", InstantiateOnFacesBlock);\r\n"]}
1
+ {"version":3,"file":"instantiateOnFacesBlock.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,qCAAqC,EAAE,MAAM,8CAA8C,CAAC;AAIrG,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAGtG;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IAkB1D;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QAnBR,qBAAg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AAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;gEAC3F;AA8OlC,aAAa,CAAC,iCAAiC,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { NodeGeometryBlock } from \"../../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../../nodeGeometryBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { NodeGeometryBuildState } from \"../../nodeGeometryBuildState\";\r\nimport type { INodeGeometryExecutionContext } from \"../../Interfaces/nodeGeometryExecutionContext\";\r\nimport type { VertexData } from \"../../../mesh.vertexData\";\r\nimport { Vector3 } from \"../../../../Maths/math.vector\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"../../../../Decorators/nodeDecorator\";\r\nimport type { Nullable } from \"../../../../types\";\r\n\r\n/**\r\n * Block used to instance geometry on every face of a geometry\r\n */\r\nexport class InstantiateOnFacesBlock extends NodeGeometryBlock implements INodeGeometryExecutionContext {\r\n private _vertexData: VertexData;\r\n private _currentFaceIndex: number;\r\n private _currentLoopIndex: number;\r\n private _currentPosition = new Vector3();\r\n private _vertex0 = new Vector3();\r\n private _vertex1 = new Vector3();\r\n private _vertex2 = new Vector3();\r\n private _tempVector0 = new Vector3();\r\n private _tempVector1 = new Vector3();\r\n\r\n /**\r\n * Gets or sets a boolean indicating that this block can evaluate context\r\n * Build performance is improved when this value is set to false as the system will cache values instead of reevaluating everything per context change\r\n */\r\n @editableInPropertyPage(\"Evaluate context\", PropertyTypeForEdition.Boolean, \"ADVANCED\", { notifiers: { rebuild: true } })\r\n public evaluateContext = true;\r\n\r\n /**\r\n * Create a new InstantiateOnFacesBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"geometry\", NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this.registerInput(\"instance\", NodeGeometryBlockConnectionPointTypes.Geometry, true);\r\n this.registerInput(\"rotation\", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.Zero());\r\n this.registerInput(\"scaling\", NodeGeometryBlockConnectionPointTypes.Vector3, true, Vector3.One());\r\n this.registerInput(\"count\", NodeGeometryBlockConnectionPointTypes.Int, true, 256);\r\n\r\n this.scaling.acceptedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Float);\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.Geometry);\r\n }\r\n\r\n /**\r\n * Gets the current index in the current flow\r\n * @returns the current index\r\n */\r\n public getExecutionIndex(): number {\r\n return 0;\r\n }\r\n\r\n /**\r\n * Gets the current face index in the current flow\r\n * @returns the current face index\r\n */\r\n public getExecutionFaceIndex(): number {\r\n return this._currentFaceIndex;\r\n }\r\n\r\n /**\r\n * Gets the current loop index in the current flow\r\n * @returns the current loop index\r\n */\r\n public getExecutionLoopIndex(): number {\r\n return this._currentLoopIndex;\r\n }\r\n\r\n /**\r\n * Gets the value associated with a contextual positions\r\n * @returns the value associated with the source\r\n */\r\n public getOverridePositionsContextualValue() {\r\n return this._currentPosition;\r\n }\r\n\r\n /**\r\n * Gets the value associated with a contextual normals\r\n * @returns the value associated with the source\r\n */\r\n public getOverrideNormalsContextualValue() {\r\n this._vertex1.subtractToRef(this._vertex0, this._tempVector0);\r\n this._vertex2.subtractToRef(this._vertex1, this._tempVector1);\r\n this._tempVector0.normalize();\r\n this._tempVector1.normalize();\r\n return Vector3.Cross(this._tempVector1, this._tempVector0);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"InstantiateOnFacesBlock\";\r\n }\r\n\r\n /**\r\n * Gets the geometry input component\r\n */\r\n public get geometry(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the instance input component\r\n */\r\n public get instance(): NodeGeometryConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the rotation input component\r\n */\r\n public get rotation(): NodeGeometryConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the scaling input component\r\n */\r\n public get scaling(): NodeGeometryConnectionPoint {\r\n return this._inputs[3];\r\n }\r\n\r\n /**\r\n * Gets the count input component\r\n */\r\n public get count(): NodeGeometryConnectionPoint {\r\n return this._inputs[4];\r\n }\r\n\r\n /**\r\n * Gets the geometry output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n protected _buildBlock(state: NodeGeometryBuildState) {\r\n const func = (state: NodeGeometryBuildState) => {\r\n state.executionContext = this;\r\n\r\n this._vertexData = this.geometry.getConnectedValue(state);\r\n state.geometryContext = this._vertexData;\r\n\r\n if (!this._vertexData || !this._vertexData.positions || !this._vertexData.indices || !this.instance.isConnected) {\r\n state.executionContext = null;\r\n state.geometryContext = null;\r\n this.output._storedValue = null;\r\n return;\r\n }\r\n\r\n // Processing\r\n let instanceGeometry: Nullable<VertexData> = null;\r\n const instanceCount = this.count.getConnectedValue(state);\r\n const faceCount = this._vertexData.indices.length / 3;\r\n const instancePerFace = instanceCount / faceCount;\r\n let accumulatedCount = 0;\r\n const additionalVertexData: VertexData[] = [];\r\n let totalDone = 0;\r\n this._currentLoopIndex = 0;\r\n\r\n for (this._currentFaceIndex = 0; this._currentFaceIndex < faceCount; this._currentFaceIndex++) {\r\n // Extract face vertices\r\n this._vertex0.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3] * 3);\r\n this._vertex1.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 1] * 3);\r\n this._vertex2.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 2] * 3);\r\n\r\n accumulatedCount += instancePerFace;\r\n const countPerFace = (accumulatedCount | 0) - totalDone;\r\n\r\n if (countPerFace < 1) {\r\n continue;\r\n }\r\n\r\n for (let faceDispatchCount = 0; faceDispatchCount < countPerFace; faceDispatchCount++) {\r\n if (totalDone >= instanceCount) {\r\n break;\r\n }\r\n\r\n // Get random point on face\r\n let x = Math.random();\r\n let y = Math.random();\r\n\r\n if (x > y) {\r\n const temp = x;\r\n x = y;\r\n y = temp;\r\n }\r\n const s = x;\r\n const t = y - x;\r\n const u = 1 - s - t;\r\n\r\n this._currentPosition.set(\r\n s * this._vertex0.x + t * this._vertex1.x + u * this._vertex2.x,\r\n s * this._vertex0.y + t * this._vertex1.y + u * this._vertex2.y,\r\n s * this._vertex0.z + t * this._vertex1.z + u * this._vertex2.z\r\n );\r\n\r\n // Clone the instance\r\n instanceGeometry = this.instance.getConnectedValue(state) as VertexData;\r\n\r\n if (!instanceGeometry || !instanceGeometry.positions || instanceGeometry.positions.length === 0) {\r\n continue;\r\n }\r\n const clone = instanceGeometry!.clone();\r\n\r\n const scaling = state.adaptInput(this.scaling, NodeGeometryBlockConnectionPointTypes.Vector3, Vector3.OneReadOnly);\r\n const rotation = this.rotation.getConnectedValue(state) || Vector3.ZeroReadOnly;\r\n state._instantiate(clone, this._currentPosition, rotation, scaling, additionalVertexData);\r\n totalDone++;\r\n this._currentLoopIndex++;\r\n }\r\n }\r\n\r\n // Merge\r\n if (additionalVertexData.length) {\r\n if (additionalVertexData.length === 1) {\r\n this._vertexData = additionalVertexData[0];\r\n } else {\r\n // We do not merge the main one as user can use a merge node if wanted\r\n const main = additionalVertexData.splice(0, 1)[0];\r\n this._vertexData = main.merge(additionalVertexData, true, false, true, true);\r\n }\r\n }\r\n\r\n return this._vertexData;\r\n };\r\n\r\n // Storage\r\n if (this.evaluateContext) {\r\n this.output._storedFunction = func;\r\n } else {\r\n this.output._storedValue = func(state);\r\n }\r\n }\r\n\r\n protected _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.evaluateContext = ${this.evaluateContext ? \"true\" : \"false\"};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.evaluateContext = this.evaluateContext;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n if (serializationObject.evaluateContext !== undefined) {\r\n this.evaluateContext = serializationObject.evaluateContext;\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.InstantiateOnFacesBlock\", InstantiateOnFacesBlock);\r\n"]}
@@ -8,7 +8,13 @@ import type { INodeGeometryExecutionContext } from "../../Interfaces/nodeGeometr
8
8
  export declare class InstantiateOnVerticesBlock extends NodeGeometryBlock implements INodeGeometryExecutionContext {
9
9
  private _vertexData;
10
10
  private _currentIndex;
11
+ private _currentLoopIndex;
11
12
  private _indexTranslation;
13
+ /**
14
+ * Gets or sets a boolean indicating that this block can evaluate context
15
+ * Build performance is improved when this value is set to false as the system will cache values instead of reevaluating everything per context change
16
+ */
17
+ evaluateContext: boolean;
12
18
  /**
13
19
  * Gets or sets a boolean indicating if the block should remove duplicated positions
14
20
  */
@@ -23,6 +29,11 @@ export declare class InstantiateOnVerticesBlock extends NodeGeometryBlock implem
23
29
  * @returns the current index
24
30
  */
25
31
  getExecutionIndex(): number;
32
+ /**
33
+ * Gets the current loop index in the current flow
34
+ * @returns the current loop index
35
+ */
36
+ getExecutionLoopIndex(): number;
26
37
  /**
27
38
  * Gets the current face index in the current flow
28
39
  * @returns the current face index