x_ite 8.9.6 → 8.10.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 (195) hide show
  1. package/build/bin/tests.pl +1 -1
  2. package/dist/assets/components/Annotation.js +13 -13
  3. package/dist/assets/components/Annotation.min.js +1 -1
  4. package/dist/assets/components/CADGeometry.js +13 -13
  5. package/dist/assets/components/CADGeometry.min.js +1 -1
  6. package/dist/assets/components/CubeMapTexturing.js +26 -26
  7. package/dist/assets/components/CubeMapTexturing.min.js +1 -1
  8. package/dist/assets/components/DIS.js +13 -13
  9. package/dist/assets/components/DIS.min.js +1 -1
  10. package/dist/assets/components/EventUtilities.js +9 -9
  11. package/dist/assets/components/EventUtilities.min.js +1 -1
  12. package/dist/assets/components/Geometry2D.js +35 -34
  13. package/dist/assets/components/Geometry2D.min.js +1 -1
  14. package/dist/assets/components/Geospatial.js +37 -37
  15. package/dist/assets/components/Geospatial.min.js +1 -1
  16. package/dist/assets/components/HAnim.js +370 -208
  17. package/dist/assets/components/HAnim.min.js +1 -1
  18. package/dist/assets/components/KeyDeviceSensor.js +8 -8
  19. package/dist/assets/components/KeyDeviceSensor.min.js +1 -1
  20. package/dist/assets/components/Layout.js +27 -30
  21. package/dist/assets/components/Layout.min.js +1 -1
  22. package/dist/assets/components/NURBS.js +26 -26
  23. package/dist/assets/components/NURBS.min.js +1 -1
  24. package/dist/assets/components/ParticleSystems.js +23 -23
  25. package/dist/assets/components/ParticleSystems.min.js +1 -1
  26. package/dist/assets/components/Picking.js +18 -18
  27. package/dist/assets/components/Picking.min.js +1 -1
  28. package/dist/assets/components/RigidBodyPhysics.js +23 -23
  29. package/dist/assets/components/RigidBodyPhysics.min.js +1 -1
  30. package/dist/assets/components/Scripting.js +37 -37
  31. package/dist/assets/components/Scripting.min.js +1 -1
  32. package/dist/assets/components/Text.js +31 -31
  33. package/dist/assets/components/Text.min.js +1 -1
  34. package/dist/assets/components/TextureProjector.js +14 -14
  35. package/dist/assets/components/TextureProjector.min.js +1 -1
  36. package/dist/assets/components/Texturing3D.js +33 -33
  37. package/dist/assets/components/Texturing3D.min.js +1 -1
  38. package/dist/assets/components/VolumeRendering.js +18 -18
  39. package/dist/assets/components/VolumeRendering.min.js +1 -1
  40. package/dist/assets/components/X_ITE.js +9 -9
  41. package/dist/assets/components/X_ITE.min.js +1 -1
  42. package/dist/x_ite.css +1 -1
  43. package/dist/x_ite.js +9157 -8799
  44. package/dist/x_ite.min.js +1 -1
  45. package/dist/x_ite.zip +0 -0
  46. package/docs/_config.yml +5 -5
  47. package/docs/_posts/components/Core/MetadataBoolean.md +1 -1
  48. package/docs/_posts/components/Core/MetadataDouble.md +1 -1
  49. package/docs/_posts/components/Core/MetadataFloat.md +1 -1
  50. package/docs/_posts/components/Core/MetadataInteger.md +1 -1
  51. package/docs/_posts/components/Core/MetadataSet.md +1 -1
  52. package/docs/_posts/components/Core/MetadataString.md +1 -1
  53. package/docs/_posts/components/Core/WorldInfo.md +1 -1
  54. package/docs/_posts/components/EventUtilities/BooleanFilter.md +2 -2
  55. package/docs/_posts/components/EventUtilities/BooleanSequencer.md +2 -2
  56. package/docs/_posts/components/EventUtilities/BooleanToggle.md +2 -2
  57. package/docs/_posts/components/EventUtilities/BooleanTrigger.md +2 -2
  58. package/docs/_posts/components/EventUtilities/IntegerSequencer.md +2 -2
  59. package/docs/_posts/components/EventUtilities/IntegerTrigger.md +2 -2
  60. package/docs/_posts/components/EventUtilities/TimeTrigger.md +2 -2
  61. package/docs/_posts/components/Geometry2D/Arc2D.md +1 -1
  62. package/docs/_posts/components/Geometry2D/ArcClose2D.md +1 -1
  63. package/docs/_posts/components/Geometry2D/Circle2D.md +1 -1
  64. package/docs/_posts/components/Geometry2D/Disk2D.md +1 -1
  65. package/docs/_posts/components/Geometry2D/Polyline2D.md +1 -1
  66. package/docs/_posts/components/Geometry2D/Polypoint2D.md +1 -1
  67. package/docs/_posts/components/Geometry2D/Rectangle2D.md +1 -1
  68. package/docs/_posts/components/HAnim/HAnimHumanoid.md +17 -17
  69. package/docs/_posts/components/Interpolation/ColorInterpolator.md +1 -1
  70. package/docs/_posts/components/Interpolation/CoordinateInterpolator.md +1 -1
  71. package/docs/_posts/components/Interpolation/CoordinateInterpolator2D.md +1 -1
  72. package/docs/_posts/components/Interpolation/NormalInterpolator.md +1 -1
  73. package/docs/_posts/components/Interpolation/OrientationInterpolator.md +1 -1
  74. package/docs/_posts/components/Interpolation/PositionInterpolator.md +1 -1
  75. package/docs/_posts/components/Interpolation/PositionInterpolator2D.md +1 -1
  76. package/docs/_posts/components/Interpolation/ScalarInterpolator.md +1 -1
  77. package/docs/_posts/components/KeyDeviceSensor/KeySensor.md +1 -1
  78. package/docs/_posts/components/KeyDeviceSensor/StringSensor.md +1 -1
  79. package/docs/_posts/components/Networking/LoadSensor.md +1 -1
  80. package/docs/_posts/components/PointingDeviceSensor/CylinderSensor.md +1 -1
  81. package/docs/_posts/components/PointingDeviceSensor/PlaneSensor.md +1 -1
  82. package/docs/_posts/components/PointingDeviceSensor/TouchSensor.md +1 -1
  83. package/docs/_posts/components/Text/Text.md +1 -1
  84. package/docs/_posts/components/Time/TimeSensor.md +1 -1
  85. package/docs/_posts/reference/browser-services.md +6 -6
  86. package/docs/laboratory/gltf-sample-viewer.html +1 -1
  87. package/package.json +1 -1
  88. package/src/assets/shaders/webgl1/Depth.vs.js +4 -4
  89. package/src/assets/shaders/webgl1/Pointing.fs.js +1 -1
  90. package/src/assets/shaders/webgl2/Depth.vs.js +7 -4
  91. package/src/assets/shaders/webgl2/LineTransform.vs.js +24 -12
  92. package/src/assets/shaders/webgl2/Pointing.fs.js +1 -1
  93. package/src/assets/shaders/webgl2/Pointing.vs.js +12 -9
  94. package/src/assets/shaders/webgl2/include/Particle.glsl.js +5 -15
  95. package/src/assets/shaders/webgl2/include/Skin.glsl.js +88 -0
  96. package/src/assets/shaders/webgl2/include/Utils.glsl.js +13 -0
  97. package/src/assets/shaders/webgl2/include/Vertex.glsl.js +17 -8
  98. package/src/bookmarks.js +54 -2
  99. package/src/tests.js +0 -360
  100. package/src/x_ite/Base/X3DArrayField.js +18 -3
  101. package/src/x_ite/Base/X3DBaseNode.js +73 -56
  102. package/src/x_ite/Base/X3DObjectArrayField.js +6 -4
  103. package/src/x_ite/Browser/Core/Context.js +14 -4
  104. package/src/x_ite/Browser/Core/Notification.js +4 -3
  105. package/src/x_ite/Browser/Core/X3DCoreContext.js +8 -8
  106. package/src/x_ite/Browser/Geometry2D/Arc2DOptions.js +4 -3
  107. package/src/x_ite/Browser/Geometry2D/ArcClose2DOptions.js +4 -3
  108. package/src/x_ite/Browser/Geometry2D/Circle2DOptions.js +6 -6
  109. package/src/x_ite/Browser/Geometry2D/Disk2DOptions.js +9 -10
  110. package/src/x_ite/Browser/Geometry3D/ConeOptions.js +5 -4
  111. package/src/x_ite/Browser/Geometry3D/CylinderOptions.js +5 -4
  112. package/src/x_ite/Browser/Geometry3D/IcoSphereOptions.js +3 -2
  113. package/src/x_ite/Browser/Geometry3D/QuadSphereOptions.js +3 -2
  114. package/src/x_ite/Browser/Layout/ScreenText.js +2 -2
  115. package/src/x_ite/Browser/Navigation/ExamineViewer.js +4 -4
  116. package/src/x_ite/Browser/Navigation/LookAtViewer.js +4 -4
  117. package/src/x_ite/Browser/Navigation/PlaneViewer.js +3 -3
  118. package/src/x_ite/Browser/Navigation/X3DFlyViewer.js +3 -3
  119. package/src/x_ite/Browser/Navigation/X3DNavigationContext.js +6 -5
  120. package/src/x_ite/Browser/Navigation/X3DViewer.js +2 -13
  121. package/src/x_ite/Browser/Networking/X3DNetworkingContext.js +5 -4
  122. package/src/x_ite/Browser/PointingDeviceSensor/PointingDevice.js +8 -18
  123. package/src/x_ite/Browser/PointingDeviceSensor/X3DPointingDeviceSensorContext.js +17 -5
  124. package/src/x_ite/Browser/Rendering/X3DRenderingContext.js +6 -5
  125. package/src/x_ite/Browser/Shaders/Shaders.js +4 -0
  126. package/src/x_ite/Browser/Shape/X3DShapeContext.js +3 -3
  127. package/src/x_ite/Browser/Sound/X3DSoundContext.js +4 -3
  128. package/src/x_ite/Browser/Text/PolygonText.js +2 -2
  129. package/src/x_ite/Browser/Texturing/X3DTexturingContext.js +1 -1
  130. package/src/x_ite/Browser/VERSION.js +1 -1
  131. package/src/x_ite/Browser/X3DBrowser.js +49 -17
  132. package/src/x_ite/Browser/X3DBrowserContext.js +8 -7
  133. package/src/x_ite/Components/Core/X3DChildNode.js +2 -5
  134. package/src/x_ite/Components/Core/X3DPrototypeInstance.js +14 -14
  135. package/src/x_ite/Components/CubeMapTexturing/ComposedCubeMapTexture.js +1 -1
  136. package/src/x_ite/Components/EnvironmentalSensor/X3DEnvironmentalSensorNode.js +1 -1
  137. package/src/x_ite/Components/Geometry3D/ElevationGrid.js +5 -2
  138. package/src/x_ite/Components/Geometry3D/Extrusion.js +24 -13
  139. package/src/x_ite/Components/Geometry3D/IndexedFaceSet.js +5 -2
  140. package/src/x_ite/Components/Geospatial/GeoElevationGrid.js +2 -2
  141. package/src/x_ite/Components/Geospatial/GeoViewpoint.js +2 -2
  142. package/src/x_ite/Components/Grouping/X3DBoundedObject.js +1 -2
  143. package/src/x_ite/Components/HAnim/HAnimHumanoid.js +314 -161
  144. package/src/x_ite/Components/HAnim/HAnimJoint.js +37 -25
  145. package/src/x_ite/Components/Layering/X3DLayerNode.js +2 -2
  146. package/src/x_ite/Components/NURBS/NurbsOrientationInterpolator.js +1 -1
  147. package/src/x_ite/Components/NURBS/NurbsPositionInterpolator.js +1 -1
  148. package/src/x_ite/Components/Navigation/NavigationInfo.js +4 -4
  149. package/src/x_ite/Components/Navigation/OrthoViewpoint.js +1 -1
  150. package/src/x_ite/Components/Navigation/X3DViewpointNode.js +12 -12
  151. package/src/x_ite/Components/Networking/X3DUrlObject.js +18 -11
  152. package/src/x_ite/Components/Rendering/IndexedLineSet.js +17 -14
  153. package/src/x_ite/Components/Rendering/LineSet.js +16 -13
  154. package/src/x_ite/Components/Rendering/PointSet.js +16 -12
  155. package/src/x_ite/Components/Rendering/X3DColorNode.js +1 -3
  156. package/src/x_ite/Components/Rendering/X3DComposedGeometryNode.js +3 -0
  157. package/src/x_ite/Components/Rendering/X3DGeometryNode.js +48 -77
  158. package/src/x_ite/Components/Rendering/X3DLineGeometryNode.js +31 -12
  159. package/src/x_ite/Components/Rendering/X3DPointGeometryNode.js +3 -0
  160. package/src/x_ite/Components/RigidBodyPhysics/RigidBody.js +3 -3
  161. package/src/x_ite/Components/RigidBodyPhysics/X3DNBodyCollidableNode.js +2 -2
  162. package/src/x_ite/Components/RigidBodyPhysics/X3DRigidJointNode.js +1 -1
  163. package/src/x_ite/Components/Shaders/X3DProgrammableShaderObject.js +24 -7
  164. package/src/x_ite/Components/Shaders/X3DVertexAttributeNode.js +1 -1
  165. package/src/x_ite/Components/Shape/FillProperties.js +1 -3
  166. package/src/x_ite/Components/Shape/X3DAppearanceNode.js +1 -3
  167. package/src/x_ite/Components/Shape/X3DMaterialNode.js +8 -6
  168. package/src/x_ite/Components/Shape/X3DOneSidedMaterialNode.js +0 -2
  169. package/src/x_ite/Components/Sound/AudioClip.js +1 -1
  170. package/src/x_ite/Components/Sound/BufferAudioSource.js +1 -1
  171. package/src/x_ite/Components/Sound/ListenerPointSource.js +2 -2
  172. package/src/x_ite/Components/Sound/MicrophoneSource.js +2 -2
  173. package/src/x_ite/Components/Sound/OscillatorSource.js +2 -2
  174. package/src/x_ite/Components/Sound/Sound.js +1 -1
  175. package/src/x_ite/Components/Sound/StreamAudioSource.js +2 -2
  176. package/src/x_ite/Components/Sound/X3DSoundProcessingNode.js +1 -1
  177. package/src/x_ite/Components/Text/X3DFontStyleNode.js +4 -4
  178. package/src/x_ite/Components/Texturing/MultiTexture.js +1 -1
  179. package/src/x_ite/Components/Texturing/PixelTexture.js +1 -1
  180. package/src/x_ite/Components/Texturing/X3DSingleTextureCoordinateNode.js +2 -2
  181. package/src/x_ite/Components/Texturing/X3DTextureNode.js +1 -3
  182. package/src/x_ite/Components/Texturing3D/ComposedTexture3D.js +2 -2
  183. package/src/x_ite/Components/Texturing3D/PixelTexture3D.js +1 -1
  184. package/src/x_ite/Components/Time/TimeSensor.js +1 -1
  185. package/src/x_ite/Components/Time/X3DTimeDependentNode.js +2 -2
  186. package/src/x_ite/Execution/X3DExecutionContext.js +3 -4
  187. package/src/x_ite/Execution/X3DScene.js +4 -4
  188. package/src/x_ite/Execution/X3DWorld.js +1 -1
  189. package/src/x_ite/Parser/GLTF2Parser.js +196 -116
  190. package/src/x_ite/Parser/X3DOptimizer.js +47 -18
  191. package/src/x_ite/Prototype/X3DExternProtoDeclaration.js +4 -4
  192. package/src/x_ite/Prototype/X3DProtoDeclarationNode.js +1 -1
  193. package/src/x_ite/Rendering/X3DRenderObject.js +20 -12
  194. package/src/x_ite.html +36 -10
  195. package/x_ite.min.html +36 -10
@@ -182,8 +182,8 @@ Object .assign (Object .setPrototypeOf (GeoElevationGrid .prototype, X3DGeometry
182
182
  normals .push (normal);
183
183
  }
184
184
 
185
- // if (!this ._normalPerVertex .getValue ())
186
- // return normals;
185
+ if (!this ._normalPerVertex .getValue ())
186
+ return normals;
187
187
 
188
188
  return this .refineNormals (normalIndex, normals, this ._creaseAngle .getValue ());
189
189
  },
@@ -64,8 +64,8 @@ function GeoViewpoint (executionContext)
64
64
 
65
65
  this .addType (X3DConstants .GeoViewpoint);
66
66
 
67
- this .addChildObjects ("navType", new Fields .MFString ("EXAMINE", "ANY"),
68
- "headlight", new Fields .SFBool (true));
67
+ this .addChildObjects (X3DConstants .inputOutput, "navType", new Fields .MFString ("EXAMINE", "ANY"),
68
+ X3DConstants .inputOutput, "headlight", new Fields .SFBool (true));
69
69
 
70
70
  if (executionContext .getSpecificationVersion () <= 3.2)
71
71
  {
@@ -46,7 +46,6 @@
46
46
  ******************************************************************************/
47
47
 
48
48
  import Fields from "../../Fields.js";
49
- import X3DCast from "../../Base/X3DCast.js";
50
49
  import X3DConstants from "../../Base/X3DConstants.js";
51
50
  import Vector3 from "../../../standard/Math/Numbers/Vector3.js";
52
51
  import Matrix4 from "../../../standard/Math/Numbers/Matrix4.js";
@@ -56,7 +55,7 @@ function X3DBoundedObject (executionContext)
56
55
  {
57
56
  this .addType (X3DConstants .X3DBoundedObject);
58
57
 
59
- this .addChildObjects ("transformSensors_changed", new Fields .SFTime ());
58
+ this .addChildObjects (X3DConstants .outputOnly, "transformSensors_changed", new Fields .SFTime ());
60
59
 
61
60
  this ._bboxSize .setUnit ("length");
62
61
  this ._bboxCenter .setUnit ("length");
@@ -55,8 +55,6 @@ import X3DBoundedObject from "../Grouping/X3DBoundedObject.js";
55
55
  import TraverseType from "../../Rendering/TraverseType.js";
56
56
  import X3DConstants from "../../Base/X3DConstants.js";
57
57
  import X3DCast from "../../Base/X3DCast.js";
58
- import Vector3 from "../../../standard/Math/Numbers/Vector3.js";
59
- import Rotation4 from "../../../standard/Math/Numbers/Rotation4.js";
60
58
  import Matrix4 from "../../../standard/Math/Numbers/Matrix4.js";
61
59
 
62
60
  function HAnimHumanoid (executionContext)
@@ -66,6 +64,10 @@ function HAnimHumanoid (executionContext)
66
64
 
67
65
  this .addType (X3DConstants .HAnimHumanoid);
68
66
 
67
+ this .addChildObjects (X3DConstants .inputOutput, "jointTextures", new Fields .SFTime (),
68
+ X3DConstants .inputOutput, "displacementsTexture", new Fields .SFTime (),
69
+ X3DConstants .inputOutput, "displacementWeightsTexture", new Fields .SFTime ());
70
+
69
71
  this ._translation .setUnit ("length");
70
72
  this ._center .setUnit ("length");
71
73
  this ._bboxSize .setUnit ("length");
@@ -77,11 +79,10 @@ function HAnimHumanoid (executionContext)
77
79
  this .transformNode = new Transform (executionContext);
78
80
  this .jointNodes = [ ];
79
81
  this .jointBindingMatrices = [ ];
80
- this .skinBindingNormal = null;
81
- this .skinBindingCoord = null;
82
- this .skinNormalNode = null;
82
+ this .displacementWeights = [ ];
83
83
  this .skinCoordNode = null;
84
- this .changed = false;
84
+ this .change = new Lock ();
85
+ this .skinning = Function .prototype;
85
86
  }
86
87
 
87
88
  Object .assign (Object .setPrototypeOf (HAnimHumanoid .prototype, X3DChildNode .prototype),
@@ -145,25 +146,64 @@ Object .assign (Object .setPrototypeOf (HAnimHumanoid .prototype, X3DChildNode .
145
146
  this .setCameraObject (this .transformNode .isCameraObject ());
146
147
  this .setPickableObject (this .transformNode .isPickableObject ());
147
148
 
148
- // Skinning
149
+ // Check WebGL version.
150
+
151
+ const
152
+ browser = this .getBrowser (),
153
+ gl = browser .getContext ();
154
+
155
+ if (gl .getVersion () === 1)
156
+ return;
157
+
158
+ // Prepare skinNode.
159
+
160
+ this .skinNode .traverse = function (humanoidNode, type, renderObject)
161
+ {
162
+ renderObject .getHumanoids () .push (humanoidNode);
163
+
164
+ Group .prototype .traverse .call (this, type, renderObject);
165
+
166
+ renderObject .getHumanoids () .pop ();
167
+ }
168
+ .bind (this .skinNode, this);
149
169
 
150
- this ._joints .addInterest ("set_joints__", this);
151
- this ._jointBindingPositions .addInterest ("set_joints__", this);
152
- this ._jointBindingRotations .addInterest ("set_joints__", this);
153
- this ._jointBindingScales .addInterest ("set_joints__", this);
154
- this ._skinBindingNormal .addInterest ("set_skinBindingNormal__", this);
155
- this ._skinBindingCoord .addInterest ("set_skinBindingCoord__", this);
156
- this ._skinNormal .addInterest ("set_skinNormal__", this);
157
- this ._skinCoord .addInterest ("set_skinCoord__", this);
170
+ // Textures
171
+
172
+ this .jointsTexture = gl .createTexture ();
173
+ this .displacementsTexture = gl .createTexture ();
174
+ this .jointMatricesTexture = gl .createTexture ();
175
+
176
+ for (const texture of [this .jointsTexture, this .displacementsTexture, this .jointMatricesTexture])
177
+ {
178
+ gl .bindTexture (gl .TEXTURE_2D, texture);
179
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_S, gl .CLAMP_TO_EDGE);
180
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_WRAP_T, gl .CLAMP_TO_EDGE);
181
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MIN_FILTER, gl .LINEAR);
182
+ gl .texParameteri (gl .TEXTURE_2D, gl .TEXTURE_MAG_FILTER, gl .LINEAR);
183
+ }
184
+
185
+ // Events
186
+
187
+ this ._joints .addInterest ("set_joints__", this);
188
+ this ._jointBindingPositions .addInterest ("set_joints__", this);
189
+ this ._jointBindingRotations .addInterest ("set_joints__", this);
190
+ this ._jointBindingScales .addInterest ("set_joints__", this);
191
+ this ._jointTextures .addInterest ("set_jointTextures__", this);
192
+ this ._displacementsTexture .addInterest ("set_displacementsTexture__", this);
193
+ this ._displacementWeightsTexture .addInterest ("set_displacementWeightsTexture__", this);
194
+ this ._skinCoord .addInterest ("set_skinCoord__", this);
158
195
 
159
196
  this .set_joints__ ();
160
- this .set_skinBindingNormal__ ();
161
- this .set_skinBindingCoord__ ();
197
+ this .set_skinCoord__ ();
162
198
  },
163
199
  getBBox (bbox, shadows)
164
200
  {
165
201
  return this .transformNode .getBBox (bbox, shadows);
166
202
  },
203
+ getMatrix ()
204
+ {
205
+ return this .transformNode .getMatrix ();
206
+ },
167
207
  set_joints__ ()
168
208
  {
169
209
  const
@@ -174,7 +214,13 @@ Object .assign (Object .setPrototypeOf (HAnimHumanoid .prototype, X3DChildNode .
174
214
  jointBindingScales = this ._jointBindingScales;
175
215
 
176
216
  for (const jointNode of jointNodes)
177
- jointNode .removeInterest ("set_joint__", this);
217
+ {
218
+ jointNode .removeInterest ("enable", this .change);
219
+ jointNode ._skinCoordIndex .removeInterest ("addEvent", this ._jointTextures);
220
+ jointNode ._skinCoordWeight .removeInterest ("addEvent", this ._jointTextures);
221
+ jointNode ._displacements .removeInterest ("addEvent", this ._displacementsTexture);
222
+ jointNode ._displacementWeights .removeInterest ("addEvent", this ._displacementWeightsTexture);
223
+ }
178
224
 
179
225
  jointNodes .length = 0;
180
226
  jointBindingMatrices .length = 0;
@@ -183,67 +229,219 @@ Object .assign (Object .setPrototypeOf (HAnimHumanoid .prototype, X3DChildNode .
183
229
  {
184
230
  const jointNode = X3DCast (X3DConstants .HAnimJoint, node);
185
231
 
186
- if (jointNode)
187
- {
188
- const jointBindingMatrix = new Matrix4 ();
232
+ if (!jointNode)
233
+ continue;
189
234
 
190
- if (jointBindingPositions .length)
191
- jointBindingMatrix .translate (jointBindingPositions [Math .min (i, jointBindingPositions .length - 1)] .getValue ());
235
+ const jointBindingMatrix = new Matrix4 ();
192
236
 
193
- if (jointBindingRotations .length)
194
- jointBindingMatrix .rotate (jointBindingRotations [Math .min (i, jointBindingRotations .length - 1)] .getValue ());
237
+ if (jointBindingPositions .length)
238
+ jointBindingMatrix .translate (jointBindingPositions [Math .min (i, jointBindingPositions .length - 1)] .getValue ());
195
239
 
196
- if (jointBindingScales .length)
197
- jointBindingMatrix .scale (jointBindingScales [Math .min (i, jointBindingScales .length - 1)] .getValue ());
240
+ if (jointBindingRotations .length)
241
+ jointBindingMatrix .rotate (jointBindingRotations [Math .min (i, jointBindingRotations .length - 1)] .getValue ());
198
242
 
199
- jointNodes .push (jointNode);
200
- jointBindingMatrices .push (jointBindingMatrix);
201
- }
243
+ if (jointBindingScales .length)
244
+ jointBindingMatrix .scale (jointBindingScales [Math .min (i, jointBindingScales .length - 1)] .getValue ());
245
+
246
+ jointNodes .push (jointNode);
247
+ jointBindingMatrices .push (jointBindingMatrix);
202
248
  }
203
249
 
204
250
  for (const jointNode of jointNodes)
205
- jointNode .addInterest ("set_joint__", this);
251
+ {
252
+ jointNode .addInterest ("enable", this .change);
253
+ jointNode ._skinCoordIndex .addInterest ("addEvent", this ._jointTextures);
254
+ jointNode ._skinCoordWeight .addInterest ("addEvent", this ._jointTextures);
255
+ jointNode ._displacements .addInterest ("addEvent", this ._displacementsTexture);
256
+ jointNode ._displacementWeights .addInterest ("addEvent", this ._displacementWeightsTexture);
257
+ }
206
258
 
207
- this .set_joint__ ();
208
- },
209
- set_joint__ ()
210
- {
211
- this .changed = true;
259
+ const size = Math .ceil (Math .sqrt (jointNodes .length * 8));
260
+
261
+ this .jointMatricesArray = new Float32Array (size * size * 4),
262
+
263
+ this ._jointTextures .addEvent ();
264
+ this ._displacementsTexture .addEvent ();
265
+ this ._displacementWeightsTexture .addEvent ();
212
266
  },
213
- set_skinBindingNormal__ ()
267
+ set_jointTextures__ ()
214
268
  {
215
- this .skinBindingNormal = X3DCast (X3DConstants .X3DNormalNode, this ._skinBindingNormal);
269
+ // Create arrays.
270
+
271
+ const
272
+ length = this .skinCoordNode ?._point .length || 1,
273
+ joints = Array .from ({ length }, () => [ ]),
274
+ weights = Array .from ({ length }, () => [ ]);
275
+
276
+ for (const [j, jointNode] of this .jointNodes .entries ())
277
+ {
278
+ const skinCoordWeight = jointNode ._skinCoordWeight .getValue ();
279
+
280
+ for (const [i, index] of jointNode ._skinCoordIndex .entries ())
281
+ {
282
+ joints [index] ?.push (j);
283
+ weights [index] ?.push (skinCoordWeight [i])
284
+ }
285
+ }
216
286
 
217
- this .set_skinNormal__ ();
287
+ const
288
+ size = Math .ceil (Math .sqrt (length * 2)) || 1,
289
+ jointsArray = new Float32Array (size * size * 4);
290
+
291
+ for (let i = 0; i < length; ++ i)
292
+ {
293
+ const j = joints [i], w = weights [i];
294
+
295
+ j .length = w .length = Math .min (j .length, 4);
296
+
297
+ jointsArray .set (j, i * 8 + 0);
298
+ jointsArray .set (w, i * 8 + 4);
299
+ }
300
+
301
+ // Upload textures.
302
+
303
+ const
304
+ browser = this .getBrowser (),
305
+ gl = browser .getContext ();
306
+
307
+ gl .bindTexture (gl .TEXTURE_2D, this .jointsTexture);
308
+ gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, size, size, 0, gl .RGBA, gl .FLOAT, jointsArray);
309
+
310
+ // Trigger update.
311
+
312
+ this .change .enable ();
218
313
  },
219
- set_skinBindingCoord__ ()
314
+ set_displacementsTexture__ ()
220
315
  {
221
- this .skinBindingCoord = X3DCast (X3DConstants .X3DCoordinateNode, this ._skinBindingCoord);
316
+ // Create array.
222
317
 
223
- this .set_skinCoord__ ();
318
+ const
319
+ length = this .skinCoordNode ?._point .length || 1,
320
+ displacements = Array .from ({ length }, () => [ ]);
321
+
322
+ for (const [j, jointNode] of this .jointNodes .entries ())
323
+ {
324
+ for (const displacerNode of jointNode .getDisplacers ())
325
+ {
326
+ const d = displacerNode ._displacements;
327
+
328
+ for (const [i, index] of displacerNode ._coordIndex .entries ())
329
+ displacements [index] ?.push (... d [i]);
330
+ }
331
+ }
332
+
333
+ const
334
+ size = even (Math .ceil (Math .sqrt (length * 2)) || 1),
335
+ displacementsArray = new Float32Array (size * size * 8);
336
+
337
+ for (let i = 0; i < length; ++ i)
338
+ {
339
+ const d = displacements [i];
340
+
341
+ d .length = Math .min (d .length, 8);
342
+
343
+ displacementsArray .set (d, i * 8);
344
+ }
345
+
346
+ // Upload texture.
347
+
348
+ const
349
+ browser = this .getBrowser (),
350
+ gl = browser .getContext ();
351
+
352
+ gl .bindTexture (gl .TEXTURE_2D, this .displacementsTexture);
353
+ gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, size, size, 0, gl .RGBA, gl .FLOAT, displacementsArray);
354
+
355
+ // Weights
356
+
357
+ const displacementWeights = this .displacementWeights;
358
+
359
+ for (let i = displacementWeights .length; i < length; ++ i)
360
+ displacementWeights [i] = [ ];
361
+
362
+ displacementWeights .length = length;
363
+
364
+ this .displacementWeightsArray = new Float32Array (size * size * 4);
365
+
366
+ // Trigger update.
367
+
368
+ this .change .enable ();
224
369
  },
225
- set_skinNormal__ ()
370
+ set_displacementWeightsTexture__ ()
226
371
  {
227
- this .skinNormalNode = X3DCast (X3DConstants .X3DNormalNode, this ._skinNormal);
372
+ // Create array.
228
373
 
229
- if (!this .skinBindingNormal && this .skinNormalNode)
230
- this .skinBindingNormal = this .skinNormalNode .copy ();
374
+ const
375
+ length = this .skinCoordNode ?._point .length || 1,
376
+ displacementWeights = this .displacementWeights;
377
+
378
+ for (const d of displacementWeights)
379
+ d .length = 0;
380
+
381
+ for (const jointNode of this .jointNodes)
382
+ {
383
+ for (const displacerNode of jointNode .getDisplacers ())
384
+ {
385
+ const weight = displacerNode ._weight;
386
+
387
+ for (const index of displacerNode ._coordIndex)
388
+ displacementWeights [index] ?.push (weight);
389
+ }
390
+ }
391
+
392
+ const
393
+ size = even (Math .ceil (Math .sqrt (length * 2)) || 1),
394
+ displacementWeightsArray = this .displacementWeightsArray;
395
+
396
+ for (let i = 0; i < length; ++ i)
397
+ {
398
+ const d = displacementWeights [i];
399
+
400
+ d .length = Math .min (d .length, 8);
401
+
402
+ displacementWeightsArray .set (d, i * 8);
403
+ }
404
+
405
+ // Upload texture.
406
+
407
+ const
408
+ browser = this .getBrowser (),
409
+ gl = browser .getContext ();
410
+
411
+ gl .bindTexture (gl .TEXTURE_2D, this .displacementsTexture);
412
+ gl .texSubImage2D (gl .TEXTURE_2D, 0, 0, size / 2, size, size / 2, gl .RGBA, gl .FLOAT, displacementWeightsArray)
231
413
 
232
- this .changed = true;
414
+ // Trigger update.
415
+
416
+ this .change .enable ();
233
417
  },
234
418
  set_skinCoord__ ()
235
419
  {
236
- this .skinCoordNode = X3DCast (X3DConstants .X3DCoordinateNode, this ._skinCoord);
420
+ if (this .skinCoordNode)
421
+ {
422
+ this .skinCoordNode .removeInterest ("addEvent", this ._jointTextures);
423
+ this .skinCoordNode .removeInterest ("addEvent", this ._displacementsTexture);
424
+ this .skinCoordNode .removeInterest ("addEvent", this ._displacementWeightsTexture);
425
+ }
237
426
 
238
- if (!this .skinBindingCoord && this .skinCoordNode)
239
- this .skinBindingCoord = this .skinCoordNode .copy ();
427
+ this .skinCoordNode = X3DCast (X3DConstants .X3DCoordinateNode, this ._skinCoord);
240
428
 
241
429
  if (this .skinCoordNode)
430
+ {
242
431
  delete this .skinning;
432
+
433
+ this .skinCoordNode .addInterest ("addEvent", this ._jointTextures);
434
+ this .skinCoordNode .addInterest ("addEvent", this ._displacementsTexture);
435
+ this .skinCoordNode .addInterest ("addEvent", this ._displacementWeightsTexture);
436
+ }
243
437
  else
244
- this .skinning = Function .prototype
438
+ {
439
+ this .skinning = Function .prototype;
440
+ }
245
441
 
246
- this .changed = true;
442
+ this ._jointTextures .addEvent ();
443
+ this ._displacementsTexture .addEvent ();
444
+ this ._displacementWeightsTexture .addEvent ();
247
445
  },
248
446
  traverse (type, renderObject)
249
447
  {
@@ -253,136 +451,67 @@ Object .assign (Object .setPrototypeOf (HAnimHumanoid .prototype, X3DChildNode .
253
451
  },
254
452
  skinning: (() =>
255
453
  {
256
- const
257
- invModelMatrix = new Matrix4 (),
258
- rest = new Vector3 (0, 0, 0),
259
- skin = new Vector3 (0, 0, 0),
260
- vector = new Vector3 (0, 0, 0),
261
- point = new Vector3 (0, 0, 0);
454
+ const invModelViewMatrix = new Matrix4 ();
262
455
 
263
456
  return function (type, renderObject)
264
457
  {
265
- if (type !== TraverseType .CAMERA)
458
+ if (type !== TraverseType .DISPLAY || this .change .lock ())
266
459
  return;
267
460
 
268
- if (!this .changed)
269
- return;
461
+ // Determine inverse model matrix of humanoid.
270
462
 
271
- this .changed = false;
463
+ invModelViewMatrix .assign (this .transformNode .getMatrix ())
464
+ .multRight (renderObject .getModelViewMatrix () .get ()) .inverse ();
465
+
466
+ // Create joint matrices.
272
467
 
273
468
  const
274
469
  jointNodes = this .jointNodes,
275
470
  jointNodesLength = jointNodes .length,
276
471
  jointBindingMatrices = this .jointBindingMatrices,
277
- skinBindingNormal = this .skinBindingNormal,
278
- skinBindingCoord = this .skinBindingCoord,
279
- skinNormalNode = this .skinNormalNode,
280
- skinCoordNode = this .skinCoordNode;
281
-
282
- // Reset skin normals and coords.
283
-
284
- if (skinNormalNode)
285
- skinNormalNode ._vector .assign (skinBindingNormal ._vector);
286
-
287
- skinCoordNode ._point .assign (skinBindingCoord ._point);
288
-
289
- // Determine inverse model matrix of humanoid.
290
-
291
- invModelMatrix .assign (this .transformNode .getMatrix ())
292
- .multRight (renderObject .getModelViewMatrix () .get ()) .inverse ();
293
-
294
- // Apply joint transformations.
472
+ jointMatricesArray = this .jointMatricesArray,
473
+ size = Math .ceil (Math .sqrt (jointNodesLength * 8));
295
474
 
296
475
  for (let i = 0; i < jointNodesLength; ++ i)
297
476
  {
298
477
  const
299
- jointNode = jointNodes [i],
300
- jointBindingMatrix = jointBindingMatrices [i],
301
- jointMatrix = jointNode .getModelMatrix () .multRight (invModelMatrix) .multLeft (jointBindingMatrix),
302
- displacerNodes = jointNode .getDisplacers (),
303
- skinCoordIndexLength = jointNode ._skinCoordIndex .length;
304
-
305
- for (const displacerNode of displacerNodes)
306
- {
307
- const
308
- coordIndex = displacerNode ._coordIndex .getValue (),
309
- coordIndexLength = displacerNode ._coordIndex .length,
310
- weight = displacerNode ._weight .getValue (),
311
- displacements = displacerNode ._displacements .getValue (),
312
- displacementsLength = displacerNode ._displacements .length;
313
-
314
- for (let i = 0; i < coordIndexLength; ++ i)
315
- {
316
- const
317
- i3 = i * 3,
318
- index = coordIndex [i],
319
- displacement = i < displacementsLength ? point .set (displacements [i3], displacements [i3 + 1], displacements [i3 + 2]) : point .assign (Vector3 .Zero);
320
-
321
- skinCoordNode .get1Point (index, skin);
322
- jointMatrix .multDirMatrix (displacement) .multiply (weight) .add (skin);
323
- skinCoordNode .set1Point (index, displacement);
324
- }
325
- }
478
+ jointNode = jointNodes [i],
479
+ jointBindingMatrix = jointBindingMatrices [i],
480
+ jointMatrix = jointNode .getModelViewMatrix () .multRight (invModelViewMatrix) .multLeft (jointBindingMatrix),
481
+ jointNormalMatrix = jointMatrix .submatrix .transpose () .inverse ();
326
482
 
327
- const
328
- normalMatrix = skinNormalNode ? jointMatrix .submatrix .transpose () .inverse () : null,
329
- skinCoordIndex = jointNode ._skinCoordIndex .getValue (),
330
- skinCoordWeight = jointNode ._skinCoordWeight .getValue (),
331
- skinCoordWeightLength = jointNode ._skinCoordWeight .length;
332
-
333
- for (let i = 0; i < skinCoordIndexLength; ++ i)
334
- {
335
- const
336
- index = skinCoordIndex [i],
337
- weight = i < skinCoordWeightLength ? skinCoordWeight [i] : 1;
338
-
339
- if (skinNormalNode)
340
- {
341
- rest .assign (skinBindingNormal .get1Vector (index, vector));
342
- skinNormalNode .get1Vector (index, skin);
343
- normalMatrix .multVecMatrix (vector) .subtract (rest) .multiply (weight) .add (skin);
344
- skinNormalNode .set1Vector (index, vector);
345
- // Let the shader normalize the normals.
346
- }
347
-
348
- //skin += (rest * J - rest) * weight
349
- rest .assign (skinBindingCoord .get1Point (index, point));
350
- skinCoordNode .get1Point (index, skin);
351
- jointMatrix .multVecMatrix (point) .subtract (rest) .multiply (weight) .add (skin);
352
- skinCoordNode .set1Point (index, point);
353
- }
483
+ jointMatricesArray .set (jointMatrix, i * 32 + 0);
484
+ jointMatricesArray .set (jointNormalMatrix, i * 32 + 16);
354
485
  }
355
- };
356
- })(),
357
- toVRMLStream (generator)
358
- {
359
- if (this .skinNormalNode)
360
- this .skinNormalNode ._vector = this .skinBindingNormal ._vector;
361
486
 
362
- if (this .skinCoordNode)
363
- this .skinCoordNode ._point = this .skinBindingCoord ._point;
487
+ // Upload textures.
364
488
 
365
- X3DChildNode .prototype .toVRMLStream .call (this, generator);
366
- },
367
- toXMLStream (generator)
368
- {
369
- if (this .skinNormalNode)
370
- this .skinNormalNode ._vector = this .skinBindingNormal ._vector;
371
-
372
- if (this .skinCoordNode)
373
- this .skinCoordNode ._point = this .skinBindingCoord ._point;
489
+ const
490
+ browser = this .getBrowser (),
491
+ gl = browser .getContext ();
374
492
 
375
- X3DChildNode .prototype .toXMLStream .call (this, generator);
376
- },
377
- toJSONStream (generator)
493
+ gl .bindTexture (gl .TEXTURE_2D, this .jointMatricesTexture);
494
+ gl .texImage2D (gl .TEXTURE_2D, 0, gl .RGBA32F, size, size, 0, gl .RGBA, gl .FLOAT, jointMatricesArray);
495
+ };
496
+ })(),
497
+ setShaderUniforms (gl, shaderObject)
378
498
  {
379
- if (this .skinNormalNode)
380
- this .skinNormalNode ._vector = this .skinBindingNormal ._vector;
499
+ const
500
+ jointsTextureTextureUnit = this .getBrowser () .getTexture2DUnit (),
501
+ displacementsTextureTextureUnit = this .getBrowser () .getTexture2DUnit (),
502
+ jointMatricesTextureUnit = this .getBrowser () .getTexture2DUnit ();
381
503
 
382
- if (this .skinCoordNode)
383
- this .skinCoordNode ._point = this .skinBindingCoord ._point;
504
+ gl .activeTexture (gl .TEXTURE0 + jointsTextureTextureUnit);
505
+ gl .bindTexture (gl .TEXTURE_2D, this .jointsTexture);
506
+ gl .uniform1i (shaderObject .x3d_JointsTexture, jointsTextureTextureUnit);
507
+
508
+ gl .activeTexture (gl .TEXTURE0 + displacementsTextureTextureUnit);
509
+ gl .bindTexture (gl .TEXTURE_2D, this .displacementsTexture);
510
+ gl .uniform1i (shaderObject .x3d_DisplacementsTexture, displacementsTextureTextureUnit);
384
511
 
385
- X3DChildNode .prototype .toJSONStream .call (this, generator);
512
+ gl .activeTexture (gl .TEXTURE0 + jointMatricesTextureUnit);
513
+ gl .bindTexture (gl .TEXTURE_2D, this .jointMatricesTexture);
514
+ gl .uniform1i (shaderObject .x3d_JointMatricesTexture, jointMatricesTextureUnit);
386
515
  },
387
516
  dispose ()
388
517
  {
@@ -421,6 +550,8 @@ Object .defineProperties (HAnimHumanoid,
421
550
  new X3DFieldDefinition (X3DConstants .inputOutput, "description", new Fields .SFString ()),
422
551
  new X3DFieldDefinition (X3DConstants .inputOutput, "name", new Fields .SFString ()),
423
552
  new X3DFieldDefinition (X3DConstants .inputOutput, "info", new Fields .MFString ()),
553
+ new X3DFieldDefinition (X3DConstants .inputOutput, "skeletalConfiguration", new Fields .SFString ("BASIC")),
554
+ new X3DFieldDefinition (X3DConstants .inputOutput, "loa", new Fields .SFInt32 (-1)),
424
555
  new X3DFieldDefinition (X3DConstants .inputOutput, "translation", new Fields .SFVec3f ()),
425
556
  new X3DFieldDefinition (X3DConstants .inputOutput, "rotation", new Fields .SFRotation ()),
426
557
  new X3DFieldDefinition (X3DConstants .inputOutput, "scale", new Fields .SFVec3f (1, 1, 1)),
@@ -430,8 +561,6 @@ Object .defineProperties (HAnimHumanoid,
430
561
  new X3DFieldDefinition (X3DConstants .inputOutput, "bboxDisplay", new Fields .SFBool ()),
431
562
  new X3DFieldDefinition (X3DConstants .initializeOnly, "bboxSize", new Fields .SFVec3f (-1, -1, -1)),
432
563
  new X3DFieldDefinition (X3DConstants .initializeOnly, "bboxCenter", new Fields .SFVec3f ()),
433
- new X3DFieldDefinition (X3DConstants .inputOutput, "loa", new Fields .SFInt32 (-1)),
434
- new X3DFieldDefinition (X3DConstants .inputOutput, "skeletalConfiguration", new Fields .SFString ("BASIC")),
435
564
  new X3DFieldDefinition (X3DConstants .inputOutput, "skeleton", new Fields .MFNode ()),
436
565
  new X3DFieldDefinition (X3DConstants .inputOutput, "viewpoints", new Fields .MFNode ()),
437
566
  new X3DFieldDefinition (X3DConstants .inputOutput, "sites", new Fields .MFNode ()),
@@ -452,4 +581,28 @@ Object .defineProperties (HAnimHumanoid,
452
581
  },
453
582
  });
454
583
 
584
+ class Lock
585
+ {
586
+ #locked = true;
587
+
588
+ enable ()
589
+ {
590
+ this .#locked = false;
591
+ }
592
+
593
+ lock ()
594
+ {
595
+ const locked = this .#locked;
596
+
597
+ this .#locked = true;
598
+
599
+ return locked;
600
+ }
601
+ }
602
+
603
+ function even (value)
604
+ {
605
+ return value + value % 2;
606
+ }
607
+
455
608
  export default HAnimHumanoid;