x_ite 8.4.3 → 8.5.3
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/.vscode/settings.json +5 -1
- package/Makefile +0 -3
- package/build/bin/components.js +173 -0
- package/build/bin/tags.pl +28 -0
- package/build/bin/tests.pl +80 -2
- package/build/bin/version.pl +12 -7
- package/dist/assets/components/Annotation.js +13 -13
- package/dist/assets/components/Annotation.min.js +1 -1
- package/dist/assets/components/CADGeometry.js +13 -13
- package/dist/assets/components/CADGeometry.min.js +1 -1
- package/dist/assets/components/CubeMapTexturing.js +28 -29
- package/dist/assets/components/CubeMapTexturing.min.js +1 -1
- package/dist/assets/components/DIS.js +13 -13
- package/dist/assets/components/DIS.min.js +1 -1
- package/dist/assets/components/EventUtilities.js +9 -9
- package/dist/assets/components/EventUtilities.min.js +1 -1
- package/dist/assets/components/Geometry2D.js +19 -19
- package/dist/assets/components/Geometry2D.min.js +1 -1
- package/dist/assets/components/Geospatial.js +33 -33
- package/dist/assets/components/Geospatial.min.js +1 -1
- package/dist/assets/components/HAnim.js +63 -42
- package/dist/assets/components/HAnim.min.js +1 -1
- package/dist/assets/components/KeyDeviceSensor.js +8 -8
- package/dist/assets/components/KeyDeviceSensor.min.js +1 -1
- package/dist/assets/components/Layout.js +37 -29
- package/dist/assets/components/Layout.min.js +1 -1
- package/dist/assets/components/NURBS.js +29 -31
- package/dist/assets/components/NURBS.min.js +1 -1
- package/dist/assets/components/ParticleSystems.js +23 -23
- package/dist/assets/components/ParticleSystems.min.js +1 -1
- package/dist/assets/components/Picking.js +19 -19
- package/dist/assets/components/Picking.min.js +1 -1
- package/dist/assets/components/RigidBodyPhysics.js +24 -19
- package/dist/assets/components/RigidBodyPhysics.min.js +1 -1
- package/dist/assets/components/Scripting.js +30 -30
- package/dist/assets/components/Scripting.min.js +1 -1
- package/dist/assets/components/Text.js +172 -594
- package/dist/assets/components/Text.min.js +1 -1
- package/dist/assets/components/TextureProjector.js +31 -47
- package/dist/assets/components/TextureProjector.min.js +1 -1
- package/dist/assets/components/Texturing3D.js +367 -346
- package/dist/assets/components/Texturing3D.min.js +1 -1
- package/dist/assets/components/VolumeRendering.js +19 -19
- package/dist/assets/components/VolumeRendering.min.js +1 -1
- package/dist/assets/components/X_ITE.js +9 -9
- package/dist/assets/components/X_ITE.min.js +1 -1
- package/dist/x_ite.css +1 -1
- package/dist/x_ite.js +12174 -3553
- package/dist/x_ite.min.js +1 -1
- package/dist/x_ite.zip +0 -0
- package/docs/_config.yml +5 -136
- package/docs/_data/nav/components-CADGeometry.yml +14 -0
- package/docs/_data/nav/components-Core.yml +16 -0
- package/docs/_data/nav/components-CubeMapTexturing.yml +8 -0
- package/docs/_data/nav/components-DIS.yml +14 -0
- package/docs/_data/nav/components-EnvironmentalEffects.yml +12 -0
- package/docs/_data/nav/components-EnvironmentalSensor.yml +8 -0
- package/docs/_data/nav/components-EventUtilities.yml +16 -0
- package/docs/_data/nav/components-Followers.yml +30 -0
- package/docs/_data/nav/components-Geometry2D.yml +18 -0
- package/docs/_data/nav/components-Geometry3D.yml +16 -0
- package/docs/_data/nav/components-Geospatial.yml +24 -0
- package/docs/_data/nav/components-Grouping.yml +10 -0
- package/docs/_data/nav/components-HAnim.yml +14 -0
- package/docs/_data/nav/components-Interpolation.yml +28 -0
- package/docs/_data/nav/components-KeyDeviceSensor.yml +6 -0
- package/docs/_data/nav/components-Layering.yml +8 -0
- package/docs/_data/nav/components-Layout.yml +12 -0
- package/docs/_data/nav/components-Lighting.yml +10 -0
- package/docs/_data/nav/components-NURBS.yml +30 -0
- package/docs/_data/nav/components-Navigation.yml +16 -0
- package/docs/_data/nav/components-Networking.yml +8 -0
- package/docs/_data/nav/components-ParticleSystems.yml +22 -0
- package/docs/_data/nav/components-Picking.yml +12 -0
- package/docs/_data/nav/components-PointingDeviceSensor.yml +10 -0
- package/docs/_data/nav/components-Rendering.yml +30 -0
- package/docs/_data/nav/components-RigidBodyPhysics.yml +30 -0
- package/docs/_data/nav/components-Scripting.yml +4 -0
- package/docs/_data/nav/components-Shaders.yml +18 -0
- package/docs/_data/nav/components-Shape.yml +22 -0
- package/docs/_data/nav/components-Sound.yml +44 -0
- package/docs/_data/nav/components-Text.yml +6 -0
- package/docs/_data/nav/components-TextureProjector.yml +6 -0
- package/docs/_data/nav/components-Texturing.yml +22 -0
- package/docs/_data/nav/components-Texturing3D.yml +18 -0
- package/docs/_data/nav/components-Time.yml +4 -0
- package/docs/_data/nav/components-VolumeRendering.yml +28 -0
- package/docs/_data/nav/components-X_ITE.yml +4 -0
- package/docs/_data/nav/main.yml +26 -0
- package/docs/_data/nav/reference.yml +18 -0
- package/docs/_data/nav/tutorials-animation-sensors-and-geometry.yml +18 -0
- package/docs/_data/nav/tutorials-basic.yml +6 -0
- package/docs/_data/nav/tutorials-optimize-your-scene.yml +6 -0
- package/docs/_data/nav/tutorials-scripts-and-prototypes.yml +12 -0
- package/docs/_data/nav/tutorials-shapes-geometry-and-appearance.yml +16 -0
- package/docs/_data/nav/tutorials-textures-lights-and-environment.yml +20 -0
- package/docs/_includes/nav.html +2 -2
- package/docs/_includes/scripts.html +2 -1
- package/docs/_posts/accessing-the-external-browser.md +1 -1
- package/docs/_posts/browser-support.md +1 -1
- package/docs/_posts/components/CADGeometry/CADAssembly.md +83 -0
- package/docs/_posts/components/CADGeometry/CADFace.md +70 -0
- package/docs/_posts/components/CADGeometry/CADLayer.md +84 -0
- package/docs/_posts/components/CADGeometry/CADPart.md +117 -0
- package/docs/_posts/components/CADGeometry/IndexedQuadSet.md +125 -0
- package/docs/_posts/components/CADGeometry/QuadSet.md +113 -0
- package/docs/_posts/components/Core/MetadataBoolean.md +90 -0
- package/docs/_posts/components/Core/MetadataDouble.md +67 -0
- package/docs/_posts/components/Core/MetadataFloat.md +67 -0
- package/docs/_posts/components/Core/MetadataInteger.md +66 -0
- package/docs/_posts/components/Core/MetadataSet.md +63 -0
- package/docs/_posts/components/Core/MetadataString.md +66 -0
- package/docs/_posts/components/Core/WorldInfo.md +54 -0
- package/docs/_posts/components/CubeMapTexturing/ComposedCubeMapTexture.md +76 -0
- package/docs/_posts/components/CubeMapTexturing/GeneratedCubeMapTexture.md +65 -0
- package/docs/_posts/components/CubeMapTexturing/ImageCubeMapTexture.md +66 -0
- package/docs/_posts/components/DIS/DISEntityManager.md +73 -0
- package/docs/_posts/components/DIS/DISEntityTypeMapping.md +88 -0
- package/docs/_posts/components/DIS/EspduTransform.md +416 -0
- package/docs/_posts/components/DIS/ReceiverPdu.md +168 -0
- package/docs/_posts/components/DIS/SignalPdu.md +168 -0
- package/docs/_posts/components/DIS/TransmitterPdu.md +232 -0
- package/docs/_posts/components/EnvironmentalEffects/Background.md +189 -0
- package/docs/_posts/components/EnvironmentalEffects/Fog.md +97 -0
- package/docs/_posts/components/EnvironmentalEffects/FogCoordinate.md +40 -0
- package/docs/_posts/components/EnvironmentalEffects/LocalFog.md +84 -0
- package/docs/_posts/components/EnvironmentalEffects/TextureBackground.md +142 -0
- package/docs/_posts/components/EnvironmentalSensor/ProximitySensor.md +90 -0
- package/docs/_posts/components/EnvironmentalSensor/TransformSensor.md +91 -0
- package/docs/_posts/components/EnvironmentalSensor/VisibilitySensor.md +73 -0
- package/docs/_posts/components/EventUtilities/BooleanFilter.md +62 -0
- package/docs/_posts/components/EventUtilities/BooleanSequencer.md +86 -0
- package/docs/_posts/components/EventUtilities/BooleanToggle.md +46 -0
- package/docs/_posts/components/EventUtilities/BooleanTrigger.md +47 -0
- package/docs/_posts/components/EventUtilities/IntegerSequencer.md +90 -0
- package/docs/_posts/components/EventUtilities/IntegerTrigger.md +51 -0
- package/docs/_posts/components/EventUtilities/TimeTrigger.md +47 -0
- package/docs/_posts/components/Followers/ColorChaser.md +77 -0
- package/docs/_posts/components/Followers/ColorDamper.md +85 -0
- package/docs/_posts/components/Followers/CoordinateChaser.md +76 -0
- package/docs/_posts/components/Followers/CoordinateDamper.md +80 -0
- package/docs/_posts/components/Followers/OrientationChaser.md +72 -0
- package/docs/_posts/components/Followers/OrientationDamper.md +80 -0
- package/docs/_posts/components/Followers/PositionChaser.md +72 -0
- package/docs/_posts/components/Followers/PositionChaser2D.md +72 -0
- package/docs/_posts/components/Followers/PositionDamper.md +80 -0
- package/docs/_posts/components/Followers/PositionDamper2D.md +80 -0
- package/docs/_posts/components/Followers/ScalarChaser.md +76 -0
- package/docs/_posts/components/Followers/ScalarDamper.md +80 -0
- package/docs/_posts/components/Followers/TexCoordChaser2D.md +72 -0
- package/docs/_posts/components/Followers/TexCoordDamper2D.md +80 -0
- package/docs/_posts/components/Geometry2D/Arc2D.md +71 -0
- package/docs/_posts/components/Geometry2D/ArcClose2D.md +91 -0
- package/docs/_posts/components/Geometry2D/Circle2D.md +55 -0
- package/docs/_posts/components/Geometry2D/Disk2D.md +75 -0
- package/docs/_posts/components/Geometry2D/Polyline2D.md +54 -0
- package/docs/_posts/components/Geometry2D/Polypoint2D.md +54 -0
- package/docs/_posts/components/Geometry2D/Rectangle2D.md +66 -0
- package/docs/_posts/components/Geometry2D/TriangleSet2D.md +66 -0
- package/docs/_posts/components/Geometry3D/Box.md +66 -0
- package/docs/_posts/components/Geometry3D/Cone.md +90 -0
- package/docs/_posts/components/Geometry3D/Cylinder.md +98 -0
- package/docs/_posts/components/Geometry3D/ElevationGrid.md +162 -0
- package/docs/_posts/components/Geometry3D/Extrusion.md +170 -0
- package/docs/_posts/components/Geometry3D/IndexedFaceSet.md +208 -0
- package/docs/_posts/components/Geometry3D/Sphere.md +66 -0
- package/docs/_posts/components/Geospatial/GeoCoordinate.md +65 -0
- package/docs/_posts/components/Geospatial/GeoElevationGrid.md +180 -0
- package/docs/_posts/components/Geospatial/GeoLOD.md +128 -0
- package/docs/_posts/components/Geospatial/GeoLocation.md +93 -0
- package/docs/_posts/components/Geospatial/GeoMetadata.md +75 -0
- package/docs/_posts/components/Geospatial/GeoOrigin.md +69 -0
- package/docs/_posts/components/Geospatial/GeoPositionInterpolator.md +95 -0
- package/docs/_posts/components/Geospatial/GeoProximitySensor.md +109 -0
- package/docs/_posts/components/Geospatial/GeoTouchSensor.md +108 -0
- package/docs/_posts/components/Geospatial/GeoTransform.md +121 -0
- package/docs/_posts/components/Geospatial/GeoViewpoint.md +126 -0
- package/docs/_posts/components/Grouping/Group.md +75 -0
- package/docs/_posts/components/Grouping/StaticGroup.md +65 -0
- package/docs/_posts/components/Grouping/Switch.md +89 -0
- package/docs/_posts/components/Grouping/Transform.md +126 -0
- package/docs/_posts/components/HAnim/HAnimDisplacer.md +89 -0
- package/docs/_posts/components/HAnim/HAnimHumanoid.md +136 -0
- package/docs/_posts/components/HAnim/HAnimJoint.md +165 -0
- package/docs/_posts/components/HAnim/HAnimMotion.md +68 -0
- package/docs/_posts/components/HAnim/HAnimSegment.md +107 -0
- package/docs/_posts/components/HAnim/HAnimSite.md +108 -0
- package/docs/_posts/components/Interpolation/ColorInterpolator.md +73 -0
- package/docs/_posts/components/Interpolation/CoordinateInterpolator.md +76 -0
- package/docs/_posts/components/Interpolation/CoordinateInterpolator2D.md +73 -0
- package/docs/_posts/components/Interpolation/EaseInEaseOut.md +67 -0
- package/docs/_posts/components/Interpolation/NormalInterpolator.md +68 -0
- package/docs/_posts/components/Interpolation/OrientationInterpolator.md +72 -0
- package/docs/_posts/components/Interpolation/PositionInterpolator.md +72 -0
- package/docs/_posts/components/Interpolation/PositionInterpolator2D.md +77 -0
- package/docs/_posts/components/Interpolation/ScalarInterpolator.md +76 -0
- package/docs/_posts/components/Interpolation/SplinePositionInterpolator.md +93 -0
- package/docs/_posts/components/Interpolation/SplinePositionInterpolator2D.md +93 -0
- package/docs/_posts/components/Interpolation/SplineScalarInterpolator.md +106 -0
- package/docs/_posts/components/Interpolation/SquadOrientationInterpolator.md +78 -0
- package/docs/_posts/components/KeyDeviceSensor/KeySensor.md +78 -0
- package/docs/_posts/components/KeyDeviceSensor/StringSensor.md +70 -0
- package/docs/_posts/components/Layering/Layer.md +67 -0
- package/docs/_posts/components/Layering/LayerSet.md +78 -0
- package/docs/_posts/components/Layering/Viewport.md +80 -0
- package/docs/_posts/components/Layout/Layout.md +107 -0
- package/docs/_posts/components/Layout/LayoutGroup.md +85 -0
- package/docs/_posts/components/Layout/LayoutLayer.md +74 -0
- package/docs/_posts/components/Layout/ScreenFontStyle.md +137 -0
- package/docs/_posts/components/Layout/ScreenGroup.md +71 -0
- package/docs/_posts/components/Lighting/DirectionalLight.md +100 -0
- package/docs/_posts/components/Lighting/EnvironmentLight.md +91 -0
- package/docs/_posts/components/Lighting/PointLight.md +103 -0
- package/docs/_posts/components/Lighting/SpotLight.md +132 -0
- package/docs/_posts/components/NURBS/Contour2D.md +57 -0
- package/docs/_posts/components/NURBS/ContourPolyline2D.md +46 -0
- package/docs/_posts/components/NURBS/CoordinateDouble.md +47 -0
- package/docs/_posts/components/NURBS/NurbsCurve.md +71 -0
- package/docs/_posts/components/NURBS/NurbsCurve2D.md +66 -0
- package/docs/_posts/components/NURBS/NurbsOrientationInterpolator.md +70 -0
- package/docs/_posts/components/NURBS/NurbsPatchSurface.md +106 -0
- package/docs/_posts/components/NURBS/NurbsPositionInterpolator.md +70 -0
- package/docs/_posts/components/NURBS/NurbsSet.md +66 -0
- package/docs/_posts/components/NURBS/NurbsSurfaceInterpolator.md +90 -0
- package/docs/_posts/components/NURBS/NurbsSweptSurface.md +69 -0
- package/docs/_posts/components/NURBS/NurbsSwungSurface.md +65 -0
- package/docs/_posts/components/NURBS/NurbsTextureCoordinate.md +77 -0
- package/docs/_posts/components/NURBS/NurbsTrimmedSurface.md +114 -0
- package/docs/_posts/components/Navigation/Billboard.md +88 -0
- package/docs/_posts/components/Navigation/Collision.md +102 -0
- package/docs/_posts/components/Navigation/LOD.md +99 -0
- package/docs/_posts/components/Navigation/NavigationInfo.md +122 -0
- package/docs/_posts/components/Navigation/OrthoViewpoint.md +117 -0
- package/docs/_posts/components/Navigation/Viewpoint.md +117 -0
- package/docs/_posts/components/Navigation/ViewpointGroup.md +80 -0
- package/docs/_posts/components/Networking/Anchor.md +111 -0
- package/docs/_posts/components/Networking/Inline.md +115 -0
- package/docs/_posts/components/Networking/LoadSensor.md +91 -0
- package/docs/_posts/components/ParticleSystems/BoundedPhysicsModel.md +54 -0
- package/docs/_posts/components/ParticleSystems/ConeEmitter.md +76 -0
- package/docs/_posts/components/ParticleSystems/ExplosionEmitter.md +72 -0
- package/docs/_posts/components/ParticleSystems/ForcePhysicsModel.md +58 -0
- package/docs/_posts/components/ParticleSystems/ParticleSystem.md +177 -0
- package/docs/_posts/components/ParticleSystems/PointEmitter.md +76 -0
- package/docs/_posts/components/ParticleSystems/PolylineEmitter.md +94 -0
- package/docs/_posts/components/ParticleSystems/SurfaceEmitter.md +90 -0
- package/docs/_posts/components/ParticleSystems/VolumeEmitter.md +90 -0
- package/docs/_posts/components/ParticleSystems/WindPhysicsModel.md +68 -0
- package/docs/_posts/components/Picking/LinePickSensor.md +125 -0
- package/docs/_posts/components/Picking/PickableGroup.md +93 -0
- package/docs/_posts/components/Picking/PointPickSensor.md +112 -0
- package/docs/_posts/components/Picking/PrimitivePickSensor.md +114 -0
- package/docs/_posts/components/Picking/VolumePickSensor.md +107 -0
- package/docs/_posts/components/PointingDeviceSensor/CylinderSensor.md +122 -0
- package/docs/_posts/components/PointingDeviceSensor/PlaneSensor.md +114 -0
- package/docs/_posts/components/PointingDeviceSensor/SphereSensor.md +89 -0
- package/docs/_posts/components/PointingDeviceSensor/TouchSensor.md +87 -0
- package/docs/_posts/components/Rendering/ClipPlane.md +67 -0
- package/docs/_posts/components/Rendering/Color.md +56 -0
- package/docs/_posts/components/Rendering/ColorRGBA.md +61 -0
- package/docs/_posts/components/Rendering/Coordinate.md +45 -0
- package/docs/_posts/components/Rendering/IndexedLineSet.md +128 -0
- package/docs/_posts/components/Rendering/IndexedTriangleFanSet.md +128 -0
- package/docs/_posts/components/Rendering/IndexedTriangleSet.md +128 -0
- package/docs/_posts/components/Rendering/IndexedTriangleStripSet.md +116 -0
- package/docs/_posts/components/Rendering/LineSet.md +85 -0
- package/docs/_posts/components/Rendering/Normal.md +41 -0
- package/docs/_posts/components/Rendering/PointSet.md +76 -0
- package/docs/_posts/components/Rendering/TriangleFanSet.md +112 -0
- package/docs/_posts/components/Rendering/TriangleSet.md +108 -0
- package/docs/_posts/components/Rendering/TriangleStripSet.md +116 -0
- package/docs/_posts/components/RigidBodyPhysics/BallJoint.md +78 -0
- package/docs/_posts/components/RigidBodyPhysics/CollidableOffset.md +75 -0
- package/docs/_posts/components/RigidBodyPhysics/CollidableShape.md +83 -0
- package/docs/_posts/components/RigidBodyPhysics/CollisionCollection.md +90 -0
- package/docs/_posts/components/RigidBodyPhysics/CollisionSensor.md +65 -0
- package/docs/_posts/components/RigidBodyPhysics/CollisionSpace.md +70 -0
- package/docs/_posts/components/RigidBodyPhysics/Contact.md +117 -0
- package/docs/_posts/components/RigidBodyPhysics/DoubleAxisHingeJoint.md +162 -0
- package/docs/_posts/components/RigidBodyPhysics/MotorJoint.md +183 -0
- package/docs/_posts/components/RigidBodyPhysics/RigidBody.md +175 -0
- package/docs/_posts/components/RigidBodyPhysics/RigidBodyCollection.md +120 -0
- package/docs/_posts/components/RigidBodyPhysics/SingleAxisHingeJoint.md +108 -0
- package/docs/_posts/components/RigidBodyPhysics/SliderJoint.md +106 -0
- package/docs/_posts/components/RigidBodyPhysics/UniversalJoint.md +119 -0
- package/docs/_posts/components/Scripting/Script.md +81 -0
- package/docs/_posts/components/Shaders/ComposedShader.md +81 -0
- package/docs/_posts/components/Shaders/FloatVertexAttribute.md +65 -0
- package/docs/_posts/components/Shaders/Matrix3VertexAttribute.md +53 -0
- package/docs/_posts/components/Shaders/Matrix4VertexAttribute.md +53 -0
- package/docs/_posts/components/Shaders/PackagedShader.md +77 -0
- package/docs/_posts/components/Shaders/ProgramShader.md +71 -0
- package/docs/_posts/components/Shaders/ShaderPart.md +76 -0
- package/docs/_posts/components/Shaders/ShaderProgram.md +68 -0
- package/docs/_posts/components/Shape/AcousticProperties.md +52 -0
- package/docs/_posts/components/Shape/Appearance.md +123 -0
- package/docs/_posts/components/Shape/FillProperties.md +67 -0
- package/docs/_posts/components/Shape/LineProperties.md +63 -0
- package/docs/_posts/components/Shape/Material.md +217 -0
- package/docs/_posts/components/Shape/PhysicalMaterial.md +173 -0
- package/docs/_posts/components/Shape/PointProperties.md +84 -0
- package/docs/_posts/components/Shape/Shape.md +63 -0
- package/docs/_posts/components/Shape/TwoSidedMaterial.md +149 -0
- package/docs/_posts/components/Shape/UnlitMaterial.md +115 -0
- package/docs/_posts/components/Sound/Analyser.md +72 -0
- package/docs/_posts/components/Sound/AudioClip.md +139 -0
- package/docs/_posts/components/Sound/AudioDestination.md +52 -0
- package/docs/_posts/components/Sound/BiquadFilter.md +70 -0
- package/docs/_posts/components/Sound/BufferAudioSource.md +86 -0
- package/docs/_posts/components/Sound/ChannelMerger.md +46 -0
- package/docs/_posts/components/Sound/ChannelSelector.md +48 -0
- package/docs/_posts/components/Sound/ChannelSplitter.md +48 -0
- package/docs/_posts/components/Sound/Convolver.md +66 -0
- package/docs/_posts/components/Sound/Delay.md +66 -0
- package/docs/_posts/components/Sound/DynamicsCompressor.md +74 -0
- package/docs/_posts/components/Sound/Gain.md +62 -0
- package/docs/_posts/components/Sound/ListenerPointSource.md +62 -0
- package/docs/_posts/components/Sound/MicrophoneSource.md +54 -0
- package/docs/_posts/components/Sound/OscillatorSource.md +58 -0
- package/docs/_posts/components/Sound/PeriodicWave.md +42 -0
- package/docs/_posts/components/Sound/Sound.md +92 -0
- package/docs/_posts/components/Sound/SpatialSound.md +68 -0
- package/docs/_posts/components/Sound/StreamAudioDestination.md +52 -0
- package/docs/_posts/components/Sound/StreamAudioSource.md +54 -0
- package/docs/_posts/components/Sound/WaveShaper.md +66 -0
- package/docs/_posts/components/Text/FontStyle.md +145 -0
- package/docs/_posts/components/Text/Text.md +102 -0
- package/docs/_posts/components/TextureProjector/TextureProjector.md +52 -0
- package/docs/_posts/components/TextureProjector/TextureProjectorParallel.md +52 -0
- package/docs/_posts/components/Texturing/ImageTexture.md +134 -0
- package/docs/_posts/components/Texturing/MovieTexture.md +221 -0
- package/docs/_posts/components/Texturing/MultiTexture.md +100 -0
- package/docs/_posts/components/Texturing/MultiTextureCoordinate.md +47 -0
- package/docs/_posts/components/Texturing/MultiTextureTransform.md +47 -0
- package/docs/_posts/components/Texturing/PixelTexture.md +80 -0
- package/docs/_posts/components/Texturing/TextureCoordinate.md +52 -0
- package/docs/_posts/components/Texturing/TextureCoordinateGenerator.md +64 -0
- package/docs/_posts/components/Texturing/TextureProperties.md +137 -0
- package/docs/_posts/components/Texturing/TextureTransform.md +73 -0
- package/docs/_posts/components/Texturing3D/ComposedTexture3D.md +76 -0
- package/docs/_posts/components/Texturing3D/ImageTexture3D.md +132 -0
- package/docs/_posts/components/Texturing3D/ImageTextureAtlas.md +131 -0
- package/docs/_posts/components/Texturing3D/PixelTexture3D.md +75 -0
- package/docs/_posts/components/Texturing3D/TextureCoordinate3D.md +53 -0
- package/docs/_posts/components/Texturing3D/TextureCoordinate4D.md +52 -0
- package/docs/_posts/components/Texturing3D/TextureTransform3D.md +69 -0
- package/docs/_posts/components/Texturing3D/TextureTransformMatrix3D.md +57 -0
- package/docs/_posts/components/Time/TimeSensor.md +136 -0
- package/docs/_posts/components/VolumeRendering/BlendedVolumeStyle.md +92 -0
- package/docs/_posts/components/VolumeRendering/BoundaryEnhancementVolumeStyle.md +53 -0
- package/docs/_posts/components/VolumeRendering/CartoonVolumeStyle.md +83 -0
- package/docs/_posts/components/VolumeRendering/ComposedVolumeStyle.md +51 -0
- package/docs/_posts/components/VolumeRendering/EdgeEnhancementVolumeStyle.md +67 -0
- package/docs/_posts/components/VolumeRendering/IsoSurfaceVolumeData.md +99 -0
- package/docs/_posts/components/VolumeRendering/OpacityMapVolumeStyle.md +51 -0
- package/docs/_posts/components/VolumeRendering/ProjectionVolumeStyle.md +48 -0
- package/docs/_posts/components/VolumeRendering/SegmentedVolumeData.md +80 -0
- package/docs/_posts/components/VolumeRendering/ShadedVolumeStyle.md +75 -0
- package/docs/_posts/components/VolumeRendering/SilhouetteEnhancementVolumeStyle.md +63 -0
- package/docs/_posts/components/VolumeRendering/ToneMappedVolumeStyle.md +71 -0
- package/docs/_posts/components/VolumeRendering/VolumeData.md +71 -0
- package/docs/_posts/components/X_ITE/BlendMode.md +94 -0
- package/docs/_posts/custom-shaders.md +9 -4
- package/docs/_posts/dom-integration.md +1 -6
- package/docs/_posts/features.md +2 -2
- package/docs/_posts/getting-started.md +100 -57
- package/docs/_posts/glossary.md +1 -1
- package/docs/_posts/how-to-configure-your-web-server.md +1 -1
- package/docs/_posts/reference/browser-services.md +78 -18
- package/docs/_posts/reference/constants-services.md +1 -1
- package/docs/_posts/reference/ecmascript-object-and-function-definitions.md +1 -1
- package/docs/_posts/reference/field-services-and-objects.md +8 -8
- package/docs/_posts/reference/prototype-services.md +7 -7
- package/docs/_posts/reference/route-services.md +1 -1
- package/docs/_posts/reference/scene-services.md +5 -5
- package/docs/_posts/reference/script-node-authoring-interface.md +1 -1
- package/docs/_posts/report-a-bug.md +1 -1
- package/docs/_posts/setup-a-localhost-server.md +5 -1
- package/docs/_posts/supported-nodes.md +239 -238
- package/docs/_posts/tutorials/adding-backgrounds.md +3 -3
- package/docs/_posts/tutorials/adding-fog.md +2 -2
- package/docs/_posts/tutorials/adding-sound.md +19 -19
- package/docs/_posts/tutorials/animating-transforms.md +17 -17
- package/docs/_posts/tutorials/basic-nodes.md +30 -30
- package/docs/_posts/tutorials/building-a-x3d-world.md +3 -3
- package/docs/_posts/tutorials/building-elevation-grids.md +7 -7
- package/docs/_posts/tutorials/building-extruded-shapes.md +7 -7
- package/docs/_posts/tutorials/building-primitive-shapes.md +13 -13
- package/docs/_posts/tutorials/building-shapes-out-of-points-lines-and-faces.md +21 -21
- package/docs/_posts/tutorials/controlling-appearance-with-materials.md +7 -7
- package/docs/_posts/tutorials/controlling-color-on-coordinate-based-geometry.md +11 -11
- package/docs/_posts/tutorials/controlling-detail.md +4 -4
- package/docs/_posts/tutorials/controlling-how-textures-are-mapped.md +7 -7
- package/docs/_posts/tutorials/controlling-navigation.md +3 -3
- package/docs/_posts/tutorials/controlling-shading-on-coordinate-based-geometry.md +13 -13
- package/docs/_posts/tutorials/controlling-the-viewpoint.md +3 -3
- package/docs/_posts/tutorials/creating-new-node-types.md +4 -4
- package/docs/_posts/tutorials/grouping-nodes.md +13 -13
- package/docs/_posts/tutorials/hello-world.md +1 -1
- package/docs/_posts/tutorials/improving-performance.md +1 -1
- package/docs/_posts/tutorials/increasing-rendering-speed.md +1 -1
- package/docs/_posts/tutorials/introducing-animation.md +10 -10
- package/docs/_posts/tutorials/introducing-script-use.md +3 -3
- package/docs/_posts/tutorials/introducing-x3d.md +1 -1
- package/docs/_posts/tutorials/lighting-your-world.md +4 -4
- package/docs/_posts/tutorials/mapping-textures.md +7 -7
- package/docs/_posts/tutorials/naming-nodes.md +1 -1
- package/docs/_posts/tutorials/overview.md +1 -1
- package/docs/_posts/tutorials/providing-information-about-your-world.md +2 -2
- package/docs/_posts/tutorials/sensing-the-viewer.md +15 -15
- package/docs/_posts/tutorials/sensing-viewer-actions.md +10 -10
- package/docs/_posts/tutorials/transforming-shapes.md +4 -4
- package/docs/_posts/tutorials/writing-program-scripts-with-ecmascript.md +5 -5
- package/docs/_posts/what's-new.md +40 -2
- package/docs/_tabs/components.md +383 -0
- package/docs/_tabs/imprint.md +1 -1
- package/docs/_tabs/laboratory.md +38 -6
- package/docs/_tabs/playground.html +22 -66
- package/docs/_tabs/reference.md +2 -1
- package/docs/_tabs/tags.md +1 -1
- package/docs/_tabs/tutorials.md +1 -1
- package/docs/assets/X3D/Michroma-Regular.ttf +0 -0
- package/docs/assets/X3D/peakpx.jpg +0 -0
- package/docs/assets/X3D/teaser.x3d +55 -0
- package/docs/assets/css/style.scss +120 -11
- package/docs/assets/img/laboratory/blend-mode.png +0 -0
- package/docs/assets/img/laboratory/dicom-nrrd.png +0 -0
- package/docs/assets/img/laboratory/earthquake.png +0 -0
- package/docs/assets/img/laboratory/gltf.png +0 -0
- package/docs/assets/img/laboratory/l-system.png +0 -0
- package/docs/assets/js/autoupdate.js +25 -0
- package/docs/laboratory/gltf-sample-viewer.html +318 -0
- package/docs/laboratory/x3d-visual-blend-mode-editor.html +1 -0
- package/package.json +9 -2
- package/src/assets/components/Texturing3D.js +5 -3
- package/src/assets/shaders/Types.glsl.js +5 -5
- package/src/assets/shaders/webgl1/PBR.fs.js +1 -1
- package/src/assets/shaders/webgl1/include/Colors.glsl.js +5 -7
- package/src/assets/shaders/webgl1/include/Fragment.glsl.js +4 -0
- package/src/assets/shaders/webgl1/include/Hatch.glsl.js +1 -1
- package/src/assets/shaders/webgl1/include/Texture.glsl.js +3 -3
- package/src/assets/shaders/webgl2/include/Colors.glsl.js +5 -7
- package/src/assets/shaders/webgl2/include/Hatch.glsl.js +1 -1
- package/src/assets/shaders/webgl2/include/Particle.glsl.js +2 -2
- package/src/assets/shaders/webgl2/include/Texture.glsl.js +2 -2
- package/src/bookmarks.js +12 -8
- package/src/examples.js +3 -0
- package/src/lib/jquery.js +20 -0
- package/src/lib/libgif/libgif.js +1004 -0
- package/src/lib/libtess.js +1 -0
- package/src/lib/nurbs/extras/sample.js +5 -7
- package/src/standard/Math/Algorithms/Bezier.js +175 -33
- package/src/standard/Math/Geometry/Box2.js +15 -55
- package/src/standard/Math/Geometry/Box3.js +19 -66
- package/src/standard/Math/Geometry/Triangle3.js +14 -79
- package/src/standard/Math/Numbers/Color3.js +4 -0
- package/src/standard/Math/Numbers/Color4.js +4 -0
- package/src/standard/Math/Numbers/Matrix3.js +11 -3
- package/src/standard/Math/Numbers/Matrix4.js +9 -6
- package/src/standard/Math/Numbers/Rotation4.js +72 -65
- package/src/tests.js +3 -0
- package/src/x_ite/Base/X3DArrayField.js +0 -2
- package/src/x_ite/Base/X3DInfoArray.js +2 -2
- package/src/x_ite/Base/X3DObjectArrayField.js +19 -0
- package/src/x_ite/Base/X3DTypedArrayField.js +149 -0
- package/src/x_ite/Browser/Core/BrowserOptions.js +108 -64
- package/src/x_ite/Browser/Core/Context.js +1 -1
- package/src/x_ite/Browser/Core/ContextMenu.js +2 -2
- package/src/x_ite/Browser/Core/Notification.js +1 -1
- package/src/x_ite/Browser/Core/RenderingProperties.js +4 -0
- package/src/x_ite/Browser/Core/X3DCoreContext.js +99 -54
- package/src/x_ite/Browser/Navigation/ExamineViewer.js +4 -14
- package/src/x_ite/Browser/Navigation/LookAtViewer.js +3 -13
- package/src/x_ite/Browser/Navigation/PlaneViewer.js +3 -12
- package/src/x_ite/Browser/Navigation/X3DFlyViewer.js +25 -22
- package/src/x_ite/Browser/Navigation/X3DViewer.js +12 -3
- package/src/x_ite/Browser/Networking/X3DNetworkingContext.js +2 -2
- package/src/x_ite/Browser/PointingDeviceSensor/PointingDevice.js +19 -15
- package/src/x_ite/Browser/Rendering/X3DRenderingContext.js +30 -10
- package/src/x_ite/Browser/Shaders/X3DShadersContext.js +1 -1
- package/src/x_ite/Browser/Shape/X3DShapeContext.js +30 -3
- package/src/x_ite/Browser/Text/PolygonText.js +137 -134
- package/src/x_ite/Browser/Texturing/GifMedia.js +113 -0
- package/src/x_ite/Browser/Texturing3D/DICOMParser.js +1 -6
- package/src/x_ite/Browser/Texturing3D/NRRDParser.js +81 -310
- package/src/x_ite/Browser/VERSION.js +1 -1
- package/src/x_ite/Browser/X3DBrowser.js +162 -122
- package/src/x_ite/Browser/X3DBrowserContext.js +7 -5
- package/src/x_ite/Components/Core/WorldInfo.js +3 -3
- package/src/x_ite/Components/Core/X3DNode.js +7 -7
- package/src/x_ite/Components/Core/X3DPrototypeInstance.js +1 -1
- package/src/x_ite/Components/CubeMapTexturing/ImageCubeMapTexture.js +2 -3
- package/src/x_ite/Components/Geometry3D/Extrusion.js +27 -23
- package/src/x_ite/Components/Geometry3D/IndexedFaceSet.js +10 -19
- package/src/x_ite/Components/Grouping/X3DBoundedObject.js +1 -3
- package/src/x_ite/Components/HAnim/HAnimHumanoid.js +39 -15
- package/src/x_ite/Components/HAnim/HAnimJoint.js +6 -9
- package/src/x_ite/Components/Layering/X3DLayerNode.js +21 -2
- package/src/x_ite/Components/Layout/Layout.js +4 -2
- package/src/x_ite/Components/Layout/ScreenFontStyle.js +6 -0
- package/src/x_ite/Components/Lighting/DirectionalLight.js +4 -11
- package/src/x_ite/Components/Lighting/EnvironmentLight.js +1 -1
- package/src/x_ite/Components/Lighting/PointLight.js +4 -11
- package/src/x_ite/Components/Lighting/SpotLight.js +4 -11
- package/src/x_ite/Components/Lighting/X3DLightNode.js +7 -9
- package/src/x_ite/Components/Navigation/OrthoViewpoint.js +2 -2
- package/src/x_ite/Components/Navigation/X3DViewpointNode.js +14 -6
- package/src/x_ite/Components/Networking/Inline.js +48 -59
- package/src/x_ite/Components/Networking/X3DUrlObject.js +1 -1
- package/src/x_ite/Components/PointingDeviceSensor/CylinderSensor.js +2 -2
- package/src/x_ite/Components/Rendering/X3DLineGeometryNode.js +7 -13
- package/src/x_ite/Components/Rendering/X3DPointGeometryNode.js +4 -2
- package/src/x_ite/Components/RigidBodyPhysics/RigidBody.js +4 -2
- package/src/x_ite/Components/Scripting/Script.js +2 -2
- package/src/x_ite/Components/Shaders/ShaderPart.js +1 -1
- package/src/x_ite/Components/Shaders/X3DProgrammableShaderObject.js +1 -3
- package/src/x_ite/Components/Shape/Appearance.js +27 -1
- package/src/x_ite/Components/Shape/FillProperties.js +1 -0
- package/src/x_ite/Components/Shape/LineProperties.js +15 -9
- package/src/x_ite/Components/Shape/Material.js +33 -22
- package/src/x_ite/Components/Shape/PhysicalMaterial.js +22 -15
- package/src/x_ite/Components/Shape/PointProperties.js +23 -7
- package/src/x_ite/Components/Shape/UnlitMaterial.js +3 -2
- package/src/x_ite/Components/Shape/X3DOneSidedMaterialNode.js +25 -19
- package/src/x_ite/Components/Sound/AudioClip.js +5 -5
- package/src/x_ite/Components/Sound/X3DSoundSourceNode.js +26 -34
- package/src/x_ite/Components/Text/X3DFontStyleNode.js +1 -1
- package/src/x_ite/Components/TextureProjector/TextureProjector.js +4 -12
- package/src/x_ite/Components/TextureProjector/TextureProjectorParallel.js +6 -14
- package/src/x_ite/Components/TextureProjector/X3DTextureProjectorNode.js +7 -7
- package/src/x_ite/Components/Texturing/ImageTexture.js +15 -10
- package/src/x_ite/Components/Texturing/MovieTexture.js +51 -11
- package/src/x_ite/Components/Texturing3D/ImageTexture3D.js +2 -2
- package/src/x_ite/Components/Texturing3D/ImageTextureAtlas.js +230 -0
- package/src/x_ite/Components/Time/X3DTimeDependentNode.js +12 -10
- package/src/x_ite/Execution/BindableList.js +35 -37
- package/src/x_ite/Execution/BindableStack.js +25 -7
- package/src/x_ite/Execution/X3DScene.js +2 -2
- package/src/x_ite/Execution/X3DWorld.js +1 -1
- package/src/x_ite/Fields/SFRotation.js +2 -1
- package/src/x_ite/Fields/SFString.js +1 -1
- package/src/x_ite/InputOutput/FileLoader.js +105 -236
- package/src/x_ite/InputOutput/Generator.js +12 -8
- package/src/x_ite/Parser/Expressions.js +85 -0
- package/src/x_ite/Parser/GLB2Parser.js +147 -0
- package/src/x_ite/Parser/GLTF2Parser.js +2221 -0
- package/src/x_ite/Parser/GoldenGate.js +64 -13
- package/src/x_ite/Parser/JSONParser.js +7 -36
- package/src/x_ite/Parser/OBJParser.js +1076 -0
- package/src/x_ite/Parser/STLAParser.js +376 -0
- package/src/x_ite/Parser/STLBParser.js +156 -0
- package/src/x_ite/Parser/SVGParser.js +2476 -0
- package/src/x_ite/Parser/VRMLParser.js +127 -183
- package/src/x_ite/Parser/X3DOptimizer.js +191 -0
- package/src/x_ite/Parser/X3DParser.js +34 -0
- package/src/x_ite/Parser/XMLParser.js +11 -109
- package/src/x_ite/Prototype/X3DExternProtoDeclaration.js +2 -2
- package/src/x_ite/Prototype/X3DProtoDeclaration.js +3 -3
- package/src/x_ite/Rendering/DependentRenderer.js +1 -1
- package/src/x_ite/Rendering/MultiSampleFrameBuffer.js +150 -0
- package/src/x_ite/Rendering/TextureBuffer.js +3 -5
- package/src/x_ite/Rendering/X3DRenderObject.js +2 -7
- package/src/x_ite/X3D.js +1 -0
- package/src/x_ite/X3DCanvas.js +10 -0
- package/src/x_ite.html +39 -17
- package/webpack.config.js +1 -0
- package/x_ite.min.html +38 -17
- package/src/standard/Networking/BinaryTransport.js +0 -116
|
@@ -0,0 +1,2221 @@
|
|
|
1
|
+
/*******************************************************************************
|
|
2
|
+
*
|
|
3
|
+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4
|
+
*
|
|
5
|
+
* Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011 - 2022.
|
|
6
|
+
*
|
|
7
|
+
* All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
|
|
8
|
+
*
|
|
9
|
+
* The copyright notice above does not evidence any actual of intended
|
|
10
|
+
* publication of such source code, and is an unpublished work by create3000.
|
|
11
|
+
* This material contains CONFIDENTIAL INFORMATION that is the property of
|
|
12
|
+
* create3000.
|
|
13
|
+
*
|
|
14
|
+
* No permission is granted to copy, distribute, or create derivative works from
|
|
15
|
+
* the contents of this software, in whole or in part, without the prior written
|
|
16
|
+
* permission of create3000.
|
|
17
|
+
*
|
|
18
|
+
* NON-MILITARY USE ONLY
|
|
19
|
+
*
|
|
20
|
+
* All create3000 software are effectively free software with a non-military use
|
|
21
|
+
* restriction. It is free. Well commented source is provided. You may reuse the
|
|
22
|
+
* source in any way you please with the exception anything that uses it must be
|
|
23
|
+
* marked to indicate is contains 'non-military use only' components.
|
|
24
|
+
*
|
|
25
|
+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
26
|
+
*
|
|
27
|
+
* Copyright 2011 - 2022, Holger Seelig <holger.seelig@yahoo.de>.
|
|
28
|
+
*
|
|
29
|
+
* This file is part of the X_ITE Project.
|
|
30
|
+
*
|
|
31
|
+
* X_ITE is free software: you can redistribute it and/or modify it under the
|
|
32
|
+
* terms of the GNU General Public License version 3 only, as published by the
|
|
33
|
+
* Free Software Foundation.
|
|
34
|
+
*
|
|
35
|
+
* X_ITE is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
36
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
37
|
+
* A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
|
|
38
|
+
* details (a copy is included in the LICENSE file that accompanied this code).
|
|
39
|
+
*
|
|
40
|
+
* You should have received a copy of the GNU General Public License version 3
|
|
41
|
+
* along with X_ITE. If not, see <https://www.gnu.org/licenses/gpl.html> for a
|
|
42
|
+
* copy of the GPLv3 License.
|
|
43
|
+
*
|
|
44
|
+
* For Silvio, Joy and Adi.
|
|
45
|
+
*
|
|
46
|
+
******************************************************************************/
|
|
47
|
+
|
|
48
|
+
import X3DParser from "./X3DParser.js";
|
|
49
|
+
import X3DOptimizer from "./X3DOptimizer.js";
|
|
50
|
+
import Vector2 from "../../standard/Math/Numbers/Vector2.js";
|
|
51
|
+
import Vector3 from "../../standard/Math/Numbers/Vector3.js";
|
|
52
|
+
import Quaternion from "../../standard/Math/Numbers/Quaternion.js";
|
|
53
|
+
import Rotation4 from "../../standard/Math/Numbers/Rotation4.js";
|
|
54
|
+
import Matrix3 from "../../standard/Math/Numbers/Matrix3.js";
|
|
55
|
+
import Matrix4 from "../../standard/Math/Numbers/Matrix4.js";
|
|
56
|
+
import Color3 from "../../standard/Math/Numbers/Color3.js";
|
|
57
|
+
import Color4 from "../../standard/Math/Numbers/Color4.js";
|
|
58
|
+
import Box3 from "../../standard/Math/Geometry/Box3.js";
|
|
59
|
+
import Algorithm from "../../standard/Math/Algorithm.js";
|
|
60
|
+
import DEBUG from "../DEBUG.js"
|
|
61
|
+
|
|
62
|
+
// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html
|
|
63
|
+
// https://github.com/KhronosGroup/glTF-Sample-Models
|
|
64
|
+
|
|
65
|
+
const
|
|
66
|
+
STEP_TIME = 1e-4, // in seconds
|
|
67
|
+
SAMPLES_PER_SECOND = 30; // in 1/s
|
|
68
|
+
|
|
69
|
+
function GLTF2Parser (scene)
|
|
70
|
+
{
|
|
71
|
+
X3DParser .call (this, scene);
|
|
72
|
+
X3DOptimizer .call (this);
|
|
73
|
+
|
|
74
|
+
// Optimizer
|
|
75
|
+
|
|
76
|
+
this .removeGroups = false;
|
|
77
|
+
this .removeEmptyGroups = true;
|
|
78
|
+
this .combineGroupingNodes = true;
|
|
79
|
+
|
|
80
|
+
// Globals
|
|
81
|
+
|
|
82
|
+
this .extensionsUsed = new Set ();
|
|
83
|
+
this .lights = [ ];
|
|
84
|
+
this .usedLights = 0;
|
|
85
|
+
this .buffers = [ ];
|
|
86
|
+
this .bufferViews = [ ];
|
|
87
|
+
this .accessors = [ ];
|
|
88
|
+
this .samplers = [ ];
|
|
89
|
+
this .materials = [ ];
|
|
90
|
+
this .textureTransformNodes = new Map ();
|
|
91
|
+
this .cameras = [ ];
|
|
92
|
+
this .viewpoints = 0;
|
|
93
|
+
this .nodes = [ ];
|
|
94
|
+
this .animations = 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
GLTF2Parser .prototype = Object .assign (Object .create (X3DParser .prototype),
|
|
98
|
+
X3DOptimizer .prototype,
|
|
99
|
+
{
|
|
100
|
+
constructor: GLTF2Parser,
|
|
101
|
+
getEncoding: function ()
|
|
102
|
+
{
|
|
103
|
+
return "JSON";
|
|
104
|
+
},
|
|
105
|
+
isValid: (function ()
|
|
106
|
+
{
|
|
107
|
+
const keys = new Set ([
|
|
108
|
+
"asset",
|
|
109
|
+
"extra",
|
|
110
|
+
"extensions",
|
|
111
|
+
"extensionsRequired",
|
|
112
|
+
"extensionsUsed",
|
|
113
|
+
"buffers",
|
|
114
|
+
"bufferViews",
|
|
115
|
+
"accessors",
|
|
116
|
+
"samplers",
|
|
117
|
+
"images",
|
|
118
|
+
"textures",
|
|
119
|
+
"materials",
|
|
120
|
+
"meshes",
|
|
121
|
+
"cameras",
|
|
122
|
+
"nodes",
|
|
123
|
+
"scenes",
|
|
124
|
+
"scene",
|
|
125
|
+
"animations",
|
|
126
|
+
"skins",
|
|
127
|
+
]);
|
|
128
|
+
|
|
129
|
+
return function ()
|
|
130
|
+
{
|
|
131
|
+
if (!(this .input instanceof Object))
|
|
132
|
+
return false;
|
|
133
|
+
|
|
134
|
+
if (!Object .keys (this .input) .every (key => keys .has (key)))
|
|
135
|
+
return false;
|
|
136
|
+
|
|
137
|
+
const asset = this .input .asset;
|
|
138
|
+
|
|
139
|
+
if (!(asset instanceof Object && asset .version === "2.0"))
|
|
140
|
+
return false;
|
|
141
|
+
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
})(),
|
|
145
|
+
setInput: function (json)
|
|
146
|
+
{
|
|
147
|
+
try
|
|
148
|
+
{
|
|
149
|
+
if (typeof json === "string")
|
|
150
|
+
json = JSON .parse (json);
|
|
151
|
+
|
|
152
|
+
this .input = json;
|
|
153
|
+
}
|
|
154
|
+
catch (error)
|
|
155
|
+
{
|
|
156
|
+
this .input = undefined;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
setBuffers: function (buffers)
|
|
160
|
+
{
|
|
161
|
+
this .buffers = buffers;
|
|
162
|
+
},
|
|
163
|
+
parseIntoScene: function (success, error)
|
|
164
|
+
{
|
|
165
|
+
this .rootObject (this .input)
|
|
166
|
+
.then (success)
|
|
167
|
+
.catch (error);
|
|
168
|
+
},
|
|
169
|
+
rootObject: async function (glTF)
|
|
170
|
+
{
|
|
171
|
+
if (!(glTF instanceof Object))
|
|
172
|
+
return;
|
|
173
|
+
|
|
174
|
+
// Set profile and components.
|
|
175
|
+
|
|
176
|
+
const
|
|
177
|
+
browser = this .getBrowser (),
|
|
178
|
+
scene = this .getScene ();
|
|
179
|
+
|
|
180
|
+
scene .setEncoding ("GLTF");
|
|
181
|
+
scene .setProfile (browser .getProfile ("Interchange"));
|
|
182
|
+
|
|
183
|
+
// Parse root objects.
|
|
184
|
+
|
|
185
|
+
this .assetObject (glTF .asset);
|
|
186
|
+
this .extensionsUsedObject (glTF .extensionsUsed);
|
|
187
|
+
this .extensionsObject (glTF .extensions);
|
|
188
|
+
|
|
189
|
+
await this .loadComponents ();
|
|
190
|
+
await this .buffersArray (glTF .buffers);
|
|
191
|
+
|
|
192
|
+
this .bufferViewsArray (glTF .bufferViews);
|
|
193
|
+
this .accessorsArray (glTF .accessors);
|
|
194
|
+
this .samplersArray (glTF .samplers);
|
|
195
|
+
|
|
196
|
+
await this .imagesArray (glTF .images);
|
|
197
|
+
|
|
198
|
+
this .texturesArray (glTF .textures);
|
|
199
|
+
this .materialsArray (glTF .materials);
|
|
200
|
+
this .meshesArray (glTF .meshes);
|
|
201
|
+
this .camerasArray (glTF .cameras);
|
|
202
|
+
this .nodesArray (glTF .nodes);
|
|
203
|
+
this .scenesArray (glTF .scenes, glTF .scene);
|
|
204
|
+
this .animationsArray (glTF .animations);
|
|
205
|
+
this .skinsArray (glTF .skins);
|
|
206
|
+
|
|
207
|
+
//this .optimizeSceneGraph (this .getExecutionContext () .getRootNodes ());
|
|
208
|
+
|
|
209
|
+
return this .getScene ();
|
|
210
|
+
},
|
|
211
|
+
assetObject: function (asset)
|
|
212
|
+
{
|
|
213
|
+
if (!(asset instanceof Object))
|
|
214
|
+
return;
|
|
215
|
+
|
|
216
|
+
const
|
|
217
|
+
scene = this .getExecutionContext (),
|
|
218
|
+
worldURL = scene .getWorldURL (),
|
|
219
|
+
worldInfoNode = scene .createNode ("WorldInfo", false);
|
|
220
|
+
|
|
221
|
+
for (const [key, value] of Object .entries (asset))
|
|
222
|
+
{
|
|
223
|
+
if (typeof value !== "string")
|
|
224
|
+
continue;
|
|
225
|
+
|
|
226
|
+
worldInfoNode ._info .push (`${key}: ${value}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (asset .extras instanceof Object)
|
|
230
|
+
{
|
|
231
|
+
for (const [key, value] of Object .entries (asset .extras))
|
|
232
|
+
{
|
|
233
|
+
if (typeof value !== "string")
|
|
234
|
+
continue;
|
|
235
|
+
|
|
236
|
+
if (key === "title")
|
|
237
|
+
worldInfoNode ._title = value;
|
|
238
|
+
else
|
|
239
|
+
worldInfoNode ._info .push (`${key}: ${value}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
worldInfoNode ._info .sort ();
|
|
244
|
+
|
|
245
|
+
if (!worldInfoNode ._title .getValue ())
|
|
246
|
+
worldInfoNode ._title = decodeURI (new URL (worldURL) .pathname .split ("/") .at (-1) || worldURL);
|
|
247
|
+
|
|
248
|
+
worldInfoNode .setup ();
|
|
249
|
+
|
|
250
|
+
scene .getRootNodes () .push (worldInfoNode);
|
|
251
|
+
},
|
|
252
|
+
extensionsUsedObject: function (extensionsUsed)
|
|
253
|
+
{
|
|
254
|
+
if (!(extensionsUsed instanceof Array))
|
|
255
|
+
return;
|
|
256
|
+
|
|
257
|
+
const
|
|
258
|
+
browser = this .getBrowser (),
|
|
259
|
+
scene = this .getExecutionContext ();
|
|
260
|
+
|
|
261
|
+
this .extensionsUsed = new Set (extensionsUsed);
|
|
262
|
+
|
|
263
|
+
for (const extension of extensionsUsed)
|
|
264
|
+
{
|
|
265
|
+
switch (extension)
|
|
266
|
+
{
|
|
267
|
+
case "KHR_texture_transform":
|
|
268
|
+
scene .addComponent (browser .getComponent ("Texturing3D", 2));
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
extensionsObject: function (extensions)
|
|
274
|
+
{
|
|
275
|
+
if (!(extensions instanceof Object))
|
|
276
|
+
return;
|
|
277
|
+
|
|
278
|
+
for (const [key, value] of Object .entries (extensions))
|
|
279
|
+
{
|
|
280
|
+
switch (key)
|
|
281
|
+
{
|
|
282
|
+
case "KHR_lights_punctual":
|
|
283
|
+
return this .khrLightsPunctualObject (value);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
khrLightsPunctualObject: function (khrLightsPunctual)
|
|
288
|
+
{
|
|
289
|
+
if (!(khrLightsPunctual instanceof Object))
|
|
290
|
+
return;
|
|
291
|
+
|
|
292
|
+
this .lightsArray (khrLightsPunctual .lights);
|
|
293
|
+
},
|
|
294
|
+
lightsArray: function (lights)
|
|
295
|
+
{
|
|
296
|
+
if (!(lights instanceof Array))
|
|
297
|
+
return;
|
|
298
|
+
|
|
299
|
+
this .lights = lights;
|
|
300
|
+
},
|
|
301
|
+
lightObject: function (light)
|
|
302
|
+
{
|
|
303
|
+
if (!(light instanceof Object))
|
|
304
|
+
return null;
|
|
305
|
+
|
|
306
|
+
const lightNode = this .lightType (light);
|
|
307
|
+
|
|
308
|
+
if (!lightNode)
|
|
309
|
+
return null;
|
|
310
|
+
|
|
311
|
+
const
|
|
312
|
+
scene = this .getExecutionContext (),
|
|
313
|
+
name = this .sanitizeName (light .name);
|
|
314
|
+
|
|
315
|
+
if (light .color instanceof Array)
|
|
316
|
+
lightNode ._color = new Color3 (... light .color);
|
|
317
|
+
|
|
318
|
+
lightNode ._intensity = this .numberValue (light .intensity, 1);
|
|
319
|
+
|
|
320
|
+
lightNode .setup ();
|
|
321
|
+
|
|
322
|
+
if (name)
|
|
323
|
+
scene .addNamedNode (scene .getUniqueName (name), lightNode);
|
|
324
|
+
|
|
325
|
+
return lightNode;
|
|
326
|
+
},
|
|
327
|
+
lightType: function (light)
|
|
328
|
+
{
|
|
329
|
+
switch (light .type)
|
|
330
|
+
{
|
|
331
|
+
case "directional":
|
|
332
|
+
return this .directionalLight (light);
|
|
333
|
+
case "spot":
|
|
334
|
+
return this .spotLight (light);
|
|
335
|
+
case "point":
|
|
336
|
+
return this .pointLight (light);
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
directionalLight: function (light)
|
|
340
|
+
{
|
|
341
|
+
const
|
|
342
|
+
scene = this .getExecutionContext (),
|
|
343
|
+
lightNode = scene .createNode ("DirectionalLight", false);
|
|
344
|
+
|
|
345
|
+
return lightNode;
|
|
346
|
+
},
|
|
347
|
+
spotLight: function (light)
|
|
348
|
+
{
|
|
349
|
+
const
|
|
350
|
+
scene = this .getExecutionContext (),
|
|
351
|
+
lightNode = scene .createNode ("SpotLight", false);
|
|
352
|
+
|
|
353
|
+
lightNode ._radius = this .numberValue (light .range, 0) || 1_000_000_000;
|
|
354
|
+
lightNode ._cutOffAngle = this .numberValue (light .outerConeAngle, Math .PI / 4);
|
|
355
|
+
lightNode ._beamWidth = this .numberValue (light .innerConeAngle, 0);
|
|
356
|
+
lightNode ._attenuation = new Vector3 (0, 0, 1);
|
|
357
|
+
|
|
358
|
+
return lightNode;
|
|
359
|
+
},
|
|
360
|
+
pointLight: function (light)
|
|
361
|
+
{
|
|
362
|
+
const
|
|
363
|
+
scene = this .getExecutionContext (),
|
|
364
|
+
lightNode = scene .createNode ("PointLight", false);
|
|
365
|
+
|
|
366
|
+
lightNode ._radius = this .numberValue (light .range, 0) || 1_000_000_000;
|
|
367
|
+
lightNode ._attenuation = new Vector3 (0, 0, 1);
|
|
368
|
+
|
|
369
|
+
return lightNode;
|
|
370
|
+
},
|
|
371
|
+
buffersArray: async function (buffers)
|
|
372
|
+
{
|
|
373
|
+
if (!(buffers instanceof Array))
|
|
374
|
+
return;
|
|
375
|
+
|
|
376
|
+
this .buffers = await Promise .all (buffers .map ((buffer, i) => this .bufferObject (buffer, i)));
|
|
377
|
+
},
|
|
378
|
+
bufferObject: function (buffer, i)
|
|
379
|
+
{
|
|
380
|
+
if (!(buffer instanceof Object))
|
|
381
|
+
return;
|
|
382
|
+
|
|
383
|
+
if (!buffer .uri)
|
|
384
|
+
return Promise .resolve (this .buffers [i]);
|
|
385
|
+
|
|
386
|
+
const url = new URL (buffer .uri, this .getExecutionContext () .getWorldURL ());
|
|
387
|
+
|
|
388
|
+
return fetch (url)
|
|
389
|
+
.then (response => response .blob ())
|
|
390
|
+
.then (blob => blob .arrayBuffer ())
|
|
391
|
+
.then (arrayBuffer => $.ungzip (arrayBuffer));
|
|
392
|
+
},
|
|
393
|
+
bufferViewsArray: function (bufferViews)
|
|
394
|
+
{
|
|
395
|
+
if (!(bufferViews instanceof Array))
|
|
396
|
+
return;
|
|
397
|
+
|
|
398
|
+
this .bufferViews = bufferViews;
|
|
399
|
+
|
|
400
|
+
for (const bufferView of bufferViews)
|
|
401
|
+
bufferView .buffer = this .bufferViewObject (bufferView);
|
|
402
|
+
},
|
|
403
|
+
bufferViewObject: function (bufferView)
|
|
404
|
+
{
|
|
405
|
+
if (!(bufferView instanceof Object))
|
|
406
|
+
return;
|
|
407
|
+
|
|
408
|
+
const buffer = this .buffers [bufferView .buffer];
|
|
409
|
+
|
|
410
|
+
if (!buffer)
|
|
411
|
+
return;
|
|
412
|
+
|
|
413
|
+
const
|
|
414
|
+
byteOffset = bufferView .byteOffset || 0,
|
|
415
|
+
byteLength = bufferView .byteLength;
|
|
416
|
+
|
|
417
|
+
return buffer .slice (byteOffset, byteOffset + byteLength);
|
|
418
|
+
},
|
|
419
|
+
accessorsArray: function (accessors)
|
|
420
|
+
{
|
|
421
|
+
if (!(accessors instanceof Array))
|
|
422
|
+
return;
|
|
423
|
+
|
|
424
|
+
this .accessors = accessors;
|
|
425
|
+
|
|
426
|
+
for (const accessor of accessors)
|
|
427
|
+
this .accessorObject (accessor);
|
|
428
|
+
},
|
|
429
|
+
accessorObject: (function ()
|
|
430
|
+
{
|
|
431
|
+
const TypedArrays = new Map ([
|
|
432
|
+
[5120, Int8Array],
|
|
433
|
+
[5121, Uint8Array],
|
|
434
|
+
[5122, Int16Array],
|
|
435
|
+
[5123, Uint16Array],
|
|
436
|
+
[5124, Int32Array],
|
|
437
|
+
[5125, Uint32Array],
|
|
438
|
+
[5126, Float32Array],
|
|
439
|
+
]);
|
|
440
|
+
|
|
441
|
+
const Components = new Map ([
|
|
442
|
+
["SCALAR", 1],
|
|
443
|
+
["VEC2", 2],
|
|
444
|
+
["VEC3", 3],
|
|
445
|
+
["VEC4", 4],
|
|
446
|
+
["MAT2", 4],
|
|
447
|
+
["MAT3", 9],
|
|
448
|
+
["MAT4", 16],
|
|
449
|
+
]);
|
|
450
|
+
|
|
451
|
+
return function (accessor)
|
|
452
|
+
{
|
|
453
|
+
if (!(accessor instanceof Object))
|
|
454
|
+
return;
|
|
455
|
+
|
|
456
|
+
Object .defineProperty (accessor, "array",
|
|
457
|
+
{
|
|
458
|
+
get: () =>
|
|
459
|
+
{
|
|
460
|
+
const
|
|
461
|
+
TypedArray = TypedArrays .get (accessor .componentType),
|
|
462
|
+
bufferView = this .bufferViews [accessor .bufferView],
|
|
463
|
+
byteOffset = accessor .byteOffset || 0,
|
|
464
|
+
byteStride = bufferView .byteStride || 0,
|
|
465
|
+
components = Components .get (accessor .type),
|
|
466
|
+
count = accessor .count || 0,
|
|
467
|
+
stride = byteStride ? byteStride / TypedArray .BYTES_PER_ELEMENT : components,
|
|
468
|
+
length = stride * count,
|
|
469
|
+
array = new TypedArray (bufferView .buffer, byteOffset, length);
|
|
470
|
+
|
|
471
|
+
if (stride === components)
|
|
472
|
+
{
|
|
473
|
+
const value = this .sparseObject (accessor .sparse, array, components);
|
|
474
|
+
|
|
475
|
+
Object .defineProperty (accessor, "array", { value: value });
|
|
476
|
+
|
|
477
|
+
return value;
|
|
478
|
+
}
|
|
479
|
+
else
|
|
480
|
+
{
|
|
481
|
+
const
|
|
482
|
+
length = count * components,
|
|
483
|
+
dense = new TypedArray (length);
|
|
484
|
+
|
|
485
|
+
for (let i = 0, j = 0; i < length; j += stride)
|
|
486
|
+
{
|
|
487
|
+
for (let c = 0; c < components; ++ c, ++ i)
|
|
488
|
+
dense [i] = array [j + c];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const value = this .sparseObject (accessor .sparse, dense, components);
|
|
492
|
+
|
|
493
|
+
Object .defineProperty (accessor, "array", { value: value });
|
|
494
|
+
|
|
495
|
+
return value;
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
configurable: true,
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
})(),
|
|
502
|
+
sparseObject: (function ()
|
|
503
|
+
{
|
|
504
|
+
const TypedArrays = new Map ([
|
|
505
|
+
[5121, Uint8Array],
|
|
506
|
+
[5123, Uint16Array],
|
|
507
|
+
[5125, Uint32Array],
|
|
508
|
+
]);
|
|
509
|
+
|
|
510
|
+
return function (sparse, array, components)
|
|
511
|
+
{
|
|
512
|
+
if (!(sparse instanceof Object))
|
|
513
|
+
return array;
|
|
514
|
+
|
|
515
|
+
if (!(sparse .indices instanceof Object))
|
|
516
|
+
return array;
|
|
517
|
+
|
|
518
|
+
if (!(sparse .values instanceof Object))
|
|
519
|
+
return array;
|
|
520
|
+
|
|
521
|
+
const
|
|
522
|
+
IndicesTypedArray = TypedArrays .get (sparse .indices .componentType),
|
|
523
|
+
indicesBufferView = this .bufferViews [sparse .indices .bufferView],
|
|
524
|
+
indicesByteOffset = sparse .indices .byteOffset,
|
|
525
|
+
indices = new IndicesTypedArray (indicesBufferView .buffer, indicesByteOffset, sparse .count);
|
|
526
|
+
|
|
527
|
+
const
|
|
528
|
+
ValuesTypedArray = array .constructor,
|
|
529
|
+
valuesBufferView = this .bufferViews [sparse .values .bufferView],
|
|
530
|
+
valuesByteOffset = sparse .values .byteOffset,
|
|
531
|
+
values = new ValuesTypedArray (valuesBufferView .buffer, valuesByteOffset, sparse .count * components);
|
|
532
|
+
|
|
533
|
+
array = array .slice ();
|
|
534
|
+
|
|
535
|
+
let v = 0;
|
|
536
|
+
|
|
537
|
+
for (const i of indices)
|
|
538
|
+
{
|
|
539
|
+
for (let c = 0; c < components; ++ c, ++ v)
|
|
540
|
+
array [i * components + c] = values [v];
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return array;
|
|
544
|
+
};
|
|
545
|
+
})(),
|
|
546
|
+
samplersArray: function (samplers)
|
|
547
|
+
{
|
|
548
|
+
if (!(samplers instanceof Array))
|
|
549
|
+
return;
|
|
550
|
+
|
|
551
|
+
this .samplers = samplers;
|
|
552
|
+
|
|
553
|
+
for (const sampler of samplers)
|
|
554
|
+
this .samplerObject (sampler);
|
|
555
|
+
},
|
|
556
|
+
samplerObject: (function ()
|
|
557
|
+
{
|
|
558
|
+
const MinificationFilters = new Map ([
|
|
559
|
+
[9728, ["NEAREST_PIXEL", false]],
|
|
560
|
+
[9729, ["AVG_PIXEL", false]],
|
|
561
|
+
[9984, ["NEAREST_PIXEL_NEAREST_MIPMAP", true]],
|
|
562
|
+
[9985, ["AVG_PIXEL_NEAREST_MIPMAP", true]],
|
|
563
|
+
[9986, ["NEAREST_PIXEL_AVG_MIPMAP", true]],
|
|
564
|
+
[9987, ["AVG_PIXEL_AVG_MIPMAP", true]],
|
|
565
|
+
]);
|
|
566
|
+
|
|
567
|
+
const MagnificationFilters = new Map ([
|
|
568
|
+
[9728, "NEAREST_PIXEL"],
|
|
569
|
+
[9729, "AVG_PIXEL"],
|
|
570
|
+
]);
|
|
571
|
+
|
|
572
|
+
const BoundaryModes = new Map ([
|
|
573
|
+
[33071, "CLAMP_TO_EDGE"],
|
|
574
|
+
[33648, "MIRRORED_REPEAT"],
|
|
575
|
+
[10497, "REPEAT"],
|
|
576
|
+
]);
|
|
577
|
+
|
|
578
|
+
return function (sampler)
|
|
579
|
+
{
|
|
580
|
+
if (!(sampler instanceof Object))
|
|
581
|
+
return;
|
|
582
|
+
|
|
583
|
+
Object .defineProperty (sampler, "texturePropertiesNode",
|
|
584
|
+
{
|
|
585
|
+
get: () =>
|
|
586
|
+
{
|
|
587
|
+
const
|
|
588
|
+
scene = this .getExecutionContext (),
|
|
589
|
+
texturePropertiesNode = scene .createNode ("TextureProperties", false),
|
|
590
|
+
name = this .sanitizeName (sampler .name);
|
|
591
|
+
|
|
592
|
+
if (name)
|
|
593
|
+
scene .addNamedNode (scene .getUniqueName (name), texturePropertiesNode);
|
|
594
|
+
|
|
595
|
+
// minFilter
|
|
596
|
+
|
|
597
|
+
const minificationFilter = MinificationFilters .get (sampler .minFilter) || ["AVG_PIXEL", false];
|
|
598
|
+
|
|
599
|
+
texturePropertiesNode ._minificationFilter = minificationFilter [0];
|
|
600
|
+
texturePropertiesNode ._generateMipMaps = minificationFilter [1];
|
|
601
|
+
|
|
602
|
+
// magFilter
|
|
603
|
+
|
|
604
|
+
texturePropertiesNode ._magnificationFilter = MagnificationFilters .get (sampler .magFilter) || "AVG_PIXEL";
|
|
605
|
+
|
|
606
|
+
// boundaryMode
|
|
607
|
+
|
|
608
|
+
texturePropertiesNode ._boundaryModeS = BoundaryModes .get (sampler .wrapS) || "REPEAT";
|
|
609
|
+
texturePropertiesNode ._boundaryModeT = BoundaryModes .get (sampler .wrapT) || "REPEAT";
|
|
610
|
+
|
|
611
|
+
// setup
|
|
612
|
+
|
|
613
|
+
texturePropertiesNode .setup ();
|
|
614
|
+
|
|
615
|
+
Object .defineProperty (sampler, "texturePropertiesNode", { value: texturePropertiesNode });
|
|
616
|
+
|
|
617
|
+
return texturePropertiesNode;
|
|
618
|
+
},
|
|
619
|
+
configurable: true,
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
})(),
|
|
623
|
+
imagesArray: async function (images)
|
|
624
|
+
{
|
|
625
|
+
if (!(images instanceof Array))
|
|
626
|
+
return;
|
|
627
|
+
|
|
628
|
+
this .images = await Promise .all (images .map (image => this .imageObject (image)));
|
|
629
|
+
},
|
|
630
|
+
imageObject: async function (image)
|
|
631
|
+
{
|
|
632
|
+
if (!(image instanceof Object))
|
|
633
|
+
return;
|
|
634
|
+
|
|
635
|
+
if (image .uri)
|
|
636
|
+
return image;
|
|
637
|
+
|
|
638
|
+
const bufferView = this .bufferViews [image .bufferView];
|
|
639
|
+
|
|
640
|
+
if (!bufferView)
|
|
641
|
+
return image;
|
|
642
|
+
|
|
643
|
+
const
|
|
644
|
+
buffer = bufferView .buffer,
|
|
645
|
+
blob = new Blob ([new Uint8Array (buffer)], { type: image .mimeType }),
|
|
646
|
+
uri = await this .blobToDataUrl (blob);
|
|
647
|
+
|
|
648
|
+
image .uri = uri;
|
|
649
|
+
|
|
650
|
+
return image;
|
|
651
|
+
},
|
|
652
|
+
blobToDataUrl: function (blob)
|
|
653
|
+
{
|
|
654
|
+
return new Promise ((resolve, reject) =>
|
|
655
|
+
{
|
|
656
|
+
const fileReader = new FileReader ();
|
|
657
|
+
|
|
658
|
+
fileReader .onload = resolve;
|
|
659
|
+
fileReader .onerror = reject;
|
|
660
|
+
|
|
661
|
+
fileReader .readAsDataURL (blob);
|
|
662
|
+
})
|
|
663
|
+
.then (event => event .target .result);
|
|
664
|
+
},
|
|
665
|
+
texturesArray: function (textures)
|
|
666
|
+
{
|
|
667
|
+
if (!(textures instanceof Array))
|
|
668
|
+
return;
|
|
669
|
+
|
|
670
|
+
this .textures = textures;
|
|
671
|
+
},
|
|
672
|
+
textureObject: function (texture)
|
|
673
|
+
{
|
|
674
|
+
if (!(texture instanceof Object))
|
|
675
|
+
return;
|
|
676
|
+
|
|
677
|
+
const image = this .images [texture .source];
|
|
678
|
+
|
|
679
|
+
if (!image)
|
|
680
|
+
return null;
|
|
681
|
+
|
|
682
|
+
if (texture .textureNode)
|
|
683
|
+
return texture .textureNode;
|
|
684
|
+
|
|
685
|
+
const
|
|
686
|
+
scene = this .getExecutionContext (),
|
|
687
|
+
textureNode = scene .createNode ("ImageTexture", false),
|
|
688
|
+
name = this .sanitizeName (texture .name || image .name);
|
|
689
|
+
|
|
690
|
+
if (name)
|
|
691
|
+
scene .addNamedNode (scene .getUniqueName (name), textureNode);
|
|
692
|
+
|
|
693
|
+
textureNode ._url = [image .uri];
|
|
694
|
+
textureNode ._flipVertically = true;
|
|
695
|
+
|
|
696
|
+
const sampler = this .samplers [texture .sampler];
|
|
697
|
+
|
|
698
|
+
if (sampler instanceof Object)
|
|
699
|
+
textureNode ._textureProperties = sampler .texturePropertiesNode;
|
|
700
|
+
|
|
701
|
+
textureNode .setup ();
|
|
702
|
+
|
|
703
|
+
return texture .textureNode = textureNode;
|
|
704
|
+
},
|
|
705
|
+
materialsArray: function (materials)
|
|
706
|
+
{
|
|
707
|
+
if (!(materials instanceof Array))
|
|
708
|
+
return;
|
|
709
|
+
|
|
710
|
+
this .materials = materials;
|
|
711
|
+
},
|
|
712
|
+
materialObject: function (material)
|
|
713
|
+
{
|
|
714
|
+
if (!(material instanceof Object))
|
|
715
|
+
return this .getDefaultAppearance ();
|
|
716
|
+
|
|
717
|
+
if (material .appearanceNode)
|
|
718
|
+
return material .appearanceNode;
|
|
719
|
+
|
|
720
|
+
if (!(material .extensions instanceof Object))
|
|
721
|
+
material .extensions = { };
|
|
722
|
+
|
|
723
|
+
const
|
|
724
|
+
scene = this .getExecutionContext (),
|
|
725
|
+
appearanceNode = scene .createNode ("Appearance", false),
|
|
726
|
+
materialNode = this .materialObjectMaterial (material),
|
|
727
|
+
name = this .sanitizeName (material .name);
|
|
728
|
+
|
|
729
|
+
const emissiveFactor = new Color3 (0, 0, 0);
|
|
730
|
+
|
|
731
|
+
if (this .vectorValue (material .emissiveFactor, emissiveFactor))
|
|
732
|
+
materialNode ._emissiveColor = emissiveFactor;
|
|
733
|
+
|
|
734
|
+
materialNode ._emissiveTextureMapping = this .textureMapping (material .emissiveTexture);
|
|
735
|
+
materialNode ._emissiveTexture = this .textureInfo (material .emissiveTexture);
|
|
736
|
+
|
|
737
|
+
this .occlusionTextureInfo (material .occlusionTexture, materialNode);
|
|
738
|
+
this .normalTextureInfo (material .normalTexture, materialNode);
|
|
739
|
+
this .materialExtensions (material .extensions, materialNode);
|
|
740
|
+
|
|
741
|
+
materialNode .setup ();
|
|
742
|
+
|
|
743
|
+
if (name)
|
|
744
|
+
scene .addNamedNode (scene .getUniqueName (name), appearanceNode);
|
|
745
|
+
|
|
746
|
+
appearanceNode ._alphaMode = this .stringValue (material .alphaMode, "OPAQUE");
|
|
747
|
+
appearanceNode ._alphaCutoff = this .numberValue (material .alphaCutoff, 0.5);
|
|
748
|
+
appearanceNode ._material = materialNode;
|
|
749
|
+
appearanceNode ._textureTransform = this .createMultiTextureTransform (materialNode);
|
|
750
|
+
|
|
751
|
+
appearanceNode .setup ();
|
|
752
|
+
|
|
753
|
+
return material .appearanceNode = appearanceNode;
|
|
754
|
+
},
|
|
755
|
+
materialObjectMaterial: function (material)
|
|
756
|
+
{
|
|
757
|
+
const materials = [
|
|
758
|
+
this .pbrMetallicRoughnessObject .bind (this, material .pbrMetallicRoughness),
|
|
759
|
+
this .pbrSpecularGlossinessObject .bind (this, material .extensions .KHR_materials_pbrSpecularGlossiness),
|
|
760
|
+
this .pbrMetallicRoughnessObject .bind (this, { }),
|
|
761
|
+
];
|
|
762
|
+
|
|
763
|
+
for (const material of materials)
|
|
764
|
+
{
|
|
765
|
+
const materialNode = material ();
|
|
766
|
+
|
|
767
|
+
if (materialNode)
|
|
768
|
+
return materialNode;
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
pbrMetallicRoughnessObject: function (pbrMetallicRoughness)
|
|
772
|
+
{
|
|
773
|
+
if (!(pbrMetallicRoughness instanceof Object))
|
|
774
|
+
return null;
|
|
775
|
+
|
|
776
|
+
const
|
|
777
|
+
scene = this .getExecutionContext (),
|
|
778
|
+
materialNode = scene .createNode ("PhysicalMaterial", false);
|
|
779
|
+
|
|
780
|
+
const
|
|
781
|
+
baseColorFactor = new Color4 (0, 0, 0, 0),
|
|
782
|
+
baseColor = new Color3 (0, 0, 0);
|
|
783
|
+
|
|
784
|
+
if (this .vectorValue (pbrMetallicRoughness .baseColorFactor, baseColorFactor))
|
|
785
|
+
{
|
|
786
|
+
materialNode ._baseColor = baseColor .set (... baseColorFactor);
|
|
787
|
+
materialNode ._transparency = 1 - baseColorFactor .a;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
materialNode ._metallic = this .numberValue (pbrMetallicRoughness .metallicFactor, 1);
|
|
791
|
+
materialNode ._roughness = this .numberValue (pbrMetallicRoughness .roughnessFactor, 1);
|
|
792
|
+
|
|
793
|
+
materialNode ._baseTextureMapping = this .textureMapping (pbrMetallicRoughness .baseColorTexture);
|
|
794
|
+
materialNode ._baseTexture = this .textureInfo (pbrMetallicRoughness .baseColorTexture);
|
|
795
|
+
materialNode ._metallicRoughnessTextureMapping = this .textureMapping (pbrMetallicRoughness .metallicRoughnessTexture);
|
|
796
|
+
materialNode ._metallicRoughnessTexture = this .textureInfo (pbrMetallicRoughness .metallicRoughnessTexture);
|
|
797
|
+
|
|
798
|
+
return materialNode;
|
|
799
|
+
},
|
|
800
|
+
pbrSpecularGlossinessObject: function (pbrSpecularGlossiness)
|
|
801
|
+
{
|
|
802
|
+
if (!(pbrSpecularGlossiness instanceof Object))
|
|
803
|
+
return null;
|
|
804
|
+
|
|
805
|
+
const
|
|
806
|
+
scene = this .getExecutionContext (),
|
|
807
|
+
materialNode = scene .createNode ("Material", false);
|
|
808
|
+
|
|
809
|
+
const
|
|
810
|
+
diffuseFactor = new Color4 (0, 0, 0, 0),
|
|
811
|
+
diffuseColor = new Color3 (0, 0, 0),
|
|
812
|
+
specularFactor = new Color3 (0, 0, 0);
|
|
813
|
+
|
|
814
|
+
if (this .vectorValue (pbrSpecularGlossiness .diffuseFactor, diffuseFactor))
|
|
815
|
+
{
|
|
816
|
+
materialNode ._diffuseColor = diffuseColor .set (... diffuseFactor);
|
|
817
|
+
materialNode ._transparency = 1 - diffuseFactor .a;
|
|
818
|
+
}
|
|
819
|
+
else
|
|
820
|
+
{
|
|
821
|
+
materialNode ._diffuseColor = Color3 .White;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
if (this .vectorValue (pbrSpecularGlossiness .specularFactor, specularFactor))
|
|
825
|
+
materialNode ._specularColor = specularFactor;
|
|
826
|
+
else
|
|
827
|
+
materialNode ._specularColor = Color3 .White;
|
|
828
|
+
|
|
829
|
+
materialNode ._shininess = this .numberValue (pbrSpecularGlossiness .glossinessFactor, 1);
|
|
830
|
+
|
|
831
|
+
materialNode ._diffuseTextureMapping = this .textureMapping (pbrSpecularGlossiness .diffuseTexture);
|
|
832
|
+
materialNode ._diffuseTexture = this .textureInfo (pbrSpecularGlossiness .diffuseTexture);
|
|
833
|
+
materialNode ._specularTextureMapping = this .textureMapping (pbrSpecularGlossiness .specularGlossinessTexture);
|
|
834
|
+
materialNode ._specularTexture = this .textureInfo (pbrSpecularGlossiness .specularGlossinessTexture);
|
|
835
|
+
materialNode ._shininessTextureMapping = this .textureMapping (pbrSpecularGlossiness .specularGlossinessTexture);
|
|
836
|
+
materialNode ._shininessTexture = this .textureInfo (pbrSpecularGlossiness .specularGlossinessTexture);
|
|
837
|
+
|
|
838
|
+
return materialNode;
|
|
839
|
+
},
|
|
840
|
+
textureMapping: function (texture)
|
|
841
|
+
{
|
|
842
|
+
if (!(texture instanceof Object))
|
|
843
|
+
return "";
|
|
844
|
+
|
|
845
|
+
return "TEXCOORD_" + (texture .texCoord || 0);
|
|
846
|
+
},
|
|
847
|
+
occlusionTextureInfo: function (occlusionTexture, materialNode)
|
|
848
|
+
{
|
|
849
|
+
if (!(occlusionTexture instanceof Object))
|
|
850
|
+
return null;
|
|
851
|
+
|
|
852
|
+
materialNode ._occlusionStrength = this .numberValue (occlusionTexture .strength, 1);
|
|
853
|
+
materialNode ._occlusionTextureMapping = this .textureMapping (occlusionTexture);
|
|
854
|
+
materialNode ._occlusionTexture = this .textureInfo (occlusionTexture);
|
|
855
|
+
},
|
|
856
|
+
normalTextureInfo: function (normalTexture, materialNode)
|
|
857
|
+
{
|
|
858
|
+
if (!(normalTexture instanceof Object))
|
|
859
|
+
return null;
|
|
860
|
+
|
|
861
|
+
materialNode ._normalScale = this .numberValue (normalTexture .scale, 1);
|
|
862
|
+
materialNode ._normalTextureMapping = this .textureMapping (normalTexture);
|
|
863
|
+
materialNode ._normalTexture = this .textureInfo (normalTexture);
|
|
864
|
+
},
|
|
865
|
+
textureInfo: function (texture)
|
|
866
|
+
{
|
|
867
|
+
if (!(texture instanceof Object))
|
|
868
|
+
return null;
|
|
869
|
+
|
|
870
|
+
if (texture .extensions instanceof Object)
|
|
871
|
+
this .textureTransformObject (texture .extensions .KHR_texture_transform, this .textureMapping (texture));
|
|
872
|
+
|
|
873
|
+
return this .textureObject (this .textures [texture .index]);
|
|
874
|
+
},
|
|
875
|
+
materialExtensions: function (extensions, materialNode)
|
|
876
|
+
{
|
|
877
|
+
if (!(extensions instanceof Object))
|
|
878
|
+
return;
|
|
879
|
+
|
|
880
|
+
for (const [key, value] of Object .entries (extensions))
|
|
881
|
+
{
|
|
882
|
+
switch (key)
|
|
883
|
+
{
|
|
884
|
+
case "KHR_materials_unlit":
|
|
885
|
+
this .khrMaterialsUnlitObject (materialNode);
|
|
886
|
+
break;
|
|
887
|
+
case "KHR_materials_emissive_strength":
|
|
888
|
+
this .khrMaterialsEmissiveStrengthObject (value, materialNode);
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
},
|
|
893
|
+
khrMaterialsUnlitObject: function (materialNode)
|
|
894
|
+
{
|
|
895
|
+
switch (materialNode .getTypeName ())
|
|
896
|
+
{
|
|
897
|
+
case "PhysicalMaterial":
|
|
898
|
+
{
|
|
899
|
+
materialNode ._emissiveColor = materialNode ._baseColor;
|
|
900
|
+
materialNode ._emissiveTextureMapping = materialNode ._baseTextureMapping;
|
|
901
|
+
materialNode ._emissiveTexture = materialNode ._baseTexture;
|
|
902
|
+
materialNode ._baseColor = Color3 .Black;
|
|
903
|
+
materialNode ._baseTextureMapping = "";
|
|
904
|
+
materialNode ._baseTexture = null;
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
case "Material":
|
|
908
|
+
{
|
|
909
|
+
materialNode ._emissiveColor = materialNode ._diffuseColor;
|
|
910
|
+
materialNode ._emissiveTextureMapping = materialNode ._diffuseTextureMapping;
|
|
911
|
+
materialNode ._emissiveTexture = materialNode ._diffuseTexture;
|
|
912
|
+
materialNode ._diffuseColor = Color3 .Black;
|
|
913
|
+
materialNode ._diffuseTextureMapping = "";
|
|
914
|
+
materialNode ._diffuseTexture = null;
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
khrMaterialsEmissiveStrengthObject: function (KHR_materials_emissive_strength, materialNode)
|
|
920
|
+
{
|
|
921
|
+
if (!(KHR_materials_emissive_strength instanceof Object))
|
|
922
|
+
return;
|
|
923
|
+
|
|
924
|
+
materialNode ._emissiveStrength = this .numberValue( KHR_materials_emissive_strength .emissiveStrength, 1);
|
|
925
|
+
},
|
|
926
|
+
textureTransformObject: function (KHR_texture_transform, mapping)
|
|
927
|
+
{
|
|
928
|
+
if (!(KHR_texture_transform instanceof Object))
|
|
929
|
+
return;
|
|
930
|
+
|
|
931
|
+
if (!this .extensionsUsed .has ("KHR_texture_transform"))
|
|
932
|
+
return;
|
|
933
|
+
|
|
934
|
+
const
|
|
935
|
+
scene = this .getExecutionContext (),
|
|
936
|
+
textureTransformNode = scene .createNode ("TextureTransformMatrix3D", false);
|
|
937
|
+
|
|
938
|
+
const
|
|
939
|
+
translation = new Vector2 (0, 0),
|
|
940
|
+
scale = new Vector2 (1, 1),
|
|
941
|
+
matrix = new Matrix4 ();
|
|
942
|
+
|
|
943
|
+
if (this .vectorValue (KHR_texture_transform .offset, translation))
|
|
944
|
+
matrix .translate (new Vector3 (... translation, 0));
|
|
945
|
+
|
|
946
|
+
matrix .rotate (new Rotation4 (0, 0, -1, this .numberValue (KHR_texture_transform .rotation, 0)));
|
|
947
|
+
|
|
948
|
+
if (this .vectorValue (KHR_texture_transform .scale, scale))
|
|
949
|
+
matrix .scale (new Vector3 (... scale, 1));
|
|
950
|
+
|
|
951
|
+
textureTransformNode ._mapping = mapping;
|
|
952
|
+
textureTransformNode ._matrix = matrix;
|
|
953
|
+
|
|
954
|
+
textureTransformNode .setup ();
|
|
955
|
+
|
|
956
|
+
this .textureTransformNodes .set (mapping, textureTransformNode);
|
|
957
|
+
},
|
|
958
|
+
meshesArray: function (meshes)
|
|
959
|
+
{
|
|
960
|
+
if (!(meshes instanceof Array))
|
|
961
|
+
return;
|
|
962
|
+
|
|
963
|
+
this .meshes = meshes;
|
|
964
|
+
},
|
|
965
|
+
meshObject: function (mesh)
|
|
966
|
+
{
|
|
967
|
+
if (!(mesh instanceof Object))
|
|
968
|
+
return;
|
|
969
|
+
|
|
970
|
+
if (mesh .shapeNodes)
|
|
971
|
+
return mesh .shapeNodes;
|
|
972
|
+
|
|
973
|
+
const shapeNodes = this .primitivesArray (mesh .primitives);
|
|
974
|
+
|
|
975
|
+
// Name Shape nodes.
|
|
976
|
+
|
|
977
|
+
const
|
|
978
|
+
scene = this .getExecutionContext (),
|
|
979
|
+
name = this .sanitizeName (mesh .name);
|
|
980
|
+
|
|
981
|
+
if (name)
|
|
982
|
+
{
|
|
983
|
+
for (const shapeNode of shapeNodes)
|
|
984
|
+
scene .addNamedNode (scene .getUniqueName (name), shapeNode);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
return mesh .shapeNodes = shapeNodes;
|
|
988
|
+
},
|
|
989
|
+
primitivesArray: function (primitives)
|
|
990
|
+
{
|
|
991
|
+
if (!(primitives instanceof Array))
|
|
992
|
+
return [ ];
|
|
993
|
+
|
|
994
|
+
const shapeNodes = [ ];
|
|
995
|
+
|
|
996
|
+
for (const primitive of primitives)
|
|
997
|
+
this .primitiveObject (primitive, shapeNodes);
|
|
998
|
+
|
|
999
|
+
return shapeNodes;
|
|
1000
|
+
},
|
|
1001
|
+
primitiveObject: function (primitive, shapeNodes)
|
|
1002
|
+
{
|
|
1003
|
+
if (!(primitive instanceof Object))
|
|
1004
|
+
return;
|
|
1005
|
+
|
|
1006
|
+
this .attributesObject (primitive .attributes);
|
|
1007
|
+
this .targetsArray (primitive .targets);
|
|
1008
|
+
|
|
1009
|
+
primitive .indices = this .accessors [primitive .indices];
|
|
1010
|
+
primitive .material = this .materials [primitive .material];
|
|
1011
|
+
|
|
1012
|
+
shapeNodes .push (this .createShape (primitive));
|
|
1013
|
+
},
|
|
1014
|
+
attributesObject: function (attributes)
|
|
1015
|
+
{
|
|
1016
|
+
if (!(attributes instanceof Object))
|
|
1017
|
+
return;
|
|
1018
|
+
|
|
1019
|
+
attributes .TANGENT = this .accessors [attributes .TANGENT];
|
|
1020
|
+
attributes .NORMAL = this .accessors [attributes .NORMAL];
|
|
1021
|
+
attributes .POSITION = this .accessors [attributes .POSITION];
|
|
1022
|
+
|
|
1023
|
+
attributes .TEXCOORD = [ ];
|
|
1024
|
+
attributes .COLOR = [ ];
|
|
1025
|
+
attributes .JOINTS = [ ];
|
|
1026
|
+
attributes .WEIGHTS = [ ];
|
|
1027
|
+
|
|
1028
|
+
for (let i = 0; Number .isInteger (attributes ["TEXCOORD_" + i]); ++ i)
|
|
1029
|
+
attributes .TEXCOORD .push (this .accessors [attributes ["TEXCOORD_" + i]]);
|
|
1030
|
+
|
|
1031
|
+
for (let i = 0; Number .isInteger (attributes ["COLOR_" + i]); ++ i)
|
|
1032
|
+
attributes .COLOR .push (this .accessors [attributes ["COLOR_" + i]]);
|
|
1033
|
+
|
|
1034
|
+
for (let i = 0; Number .isInteger (attributes ["JOINTS_" + i]); ++ i)
|
|
1035
|
+
attributes .JOINTS .push (this .accessors [attributes ["JOINTS_" + i]]);
|
|
1036
|
+
|
|
1037
|
+
for (let i = 0; Number .isInteger (attributes ["WEIGHTS_" + i]); ++ i)
|
|
1038
|
+
attributes .WEIGHTS .push (this .accessors [attributes ["WEIGHTS_" + i]]);
|
|
1039
|
+
},
|
|
1040
|
+
targetsArray: function (targets)
|
|
1041
|
+
{
|
|
1042
|
+
if (!(targets instanceof Array))
|
|
1043
|
+
return;
|
|
1044
|
+
},
|
|
1045
|
+
camerasArray: function (cameras)
|
|
1046
|
+
{
|
|
1047
|
+
if (!(cameras instanceof Array))
|
|
1048
|
+
return;
|
|
1049
|
+
|
|
1050
|
+
this .cameras = cameras;
|
|
1051
|
+
},
|
|
1052
|
+
cameraObject: function (camera)
|
|
1053
|
+
{
|
|
1054
|
+
if (!(camera instanceof Object))
|
|
1055
|
+
return null;
|
|
1056
|
+
|
|
1057
|
+
if (camera .viewpointNode !== undefined)
|
|
1058
|
+
return camera .viewpointNode;
|
|
1059
|
+
|
|
1060
|
+
const viewpointNode = this .cameraType (camera);
|
|
1061
|
+
|
|
1062
|
+
if (!viewpointNode)
|
|
1063
|
+
return camera .viewpointNode = null;
|
|
1064
|
+
|
|
1065
|
+
const
|
|
1066
|
+
scene = this .getExecutionContext (),
|
|
1067
|
+
name = this .sanitizeName (camera .name);
|
|
1068
|
+
|
|
1069
|
+
// Name
|
|
1070
|
+
|
|
1071
|
+
if (name)
|
|
1072
|
+
scene .addNamedNode (scene .getUniqueName (name), viewpointNode);
|
|
1073
|
+
|
|
1074
|
+
if (camera .name)
|
|
1075
|
+
viewpointNode ._description = camera .name;
|
|
1076
|
+
else
|
|
1077
|
+
viewpointNode ._description = `Viewpoint ${++ this .viewpoints}`;
|
|
1078
|
+
|
|
1079
|
+
viewpointNode ._position = Vector3 .Zero;
|
|
1080
|
+
viewpointNode ._centerOfRotation = new Vector3 (0, 0, -10);
|
|
1081
|
+
|
|
1082
|
+
return camera .viewpointNode = viewpointNode;
|
|
1083
|
+
},
|
|
1084
|
+
cameraType: function (camera)
|
|
1085
|
+
{
|
|
1086
|
+
switch (camera .type)
|
|
1087
|
+
{
|
|
1088
|
+
case "orthographic":
|
|
1089
|
+
return this .orthographicCamera (camera .orthographic);
|
|
1090
|
+
case "perspective":
|
|
1091
|
+
return this .perspectiveCamera (camera .perspective);
|
|
1092
|
+
default:
|
|
1093
|
+
return null;
|
|
1094
|
+
}
|
|
1095
|
+
},
|
|
1096
|
+
orthographicCamera: function (camera)
|
|
1097
|
+
{
|
|
1098
|
+
const
|
|
1099
|
+
scene = this .getExecutionContext (),
|
|
1100
|
+
viewpointNode = scene .createNode ("OrthoViewpoint", false);
|
|
1101
|
+
|
|
1102
|
+
if (typeof camera .xmag === "number")
|
|
1103
|
+
{
|
|
1104
|
+
viewpointNode ._fieldOfView [0] = -camera .xmag / 2;
|
|
1105
|
+
viewpointNode ._fieldOfView [2] = +camera .xmag / 2;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
if (typeof camera .ymag === "number")
|
|
1109
|
+
{
|
|
1110
|
+
viewpointNode ._fieldOfView [1] = -camera .ymag / 2;
|
|
1111
|
+
viewpointNode ._fieldOfView [3] = +camera .ymag / 2;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
if (typeof camera .znear === "number")
|
|
1115
|
+
viewpointNode ._nearDistance = camera .znear;
|
|
1116
|
+
|
|
1117
|
+
if (typeof camera .zfar === "number")
|
|
1118
|
+
viewpointNode ._farDistance = camera .zfar;
|
|
1119
|
+
|
|
1120
|
+
viewpointNode .setup ();
|
|
1121
|
+
|
|
1122
|
+
return viewpointNode;
|
|
1123
|
+
},
|
|
1124
|
+
perspectiveCamera: function (camera)
|
|
1125
|
+
{
|
|
1126
|
+
const
|
|
1127
|
+
scene = this .getExecutionContext (),
|
|
1128
|
+
viewpointNode = scene .createNode ("Viewpoint", false);
|
|
1129
|
+
|
|
1130
|
+
if (typeof camera .yfov === "number")
|
|
1131
|
+
viewpointNode ._fieldOfView = camera .yfov
|
|
1132
|
+
|
|
1133
|
+
if (typeof camera .znear === "number")
|
|
1134
|
+
viewpointNode ._nearDistance = camera .znear;
|
|
1135
|
+
|
|
1136
|
+
if (typeof camera .zfar === "number")
|
|
1137
|
+
viewpointNode ._farDistance = camera .zfar;
|
|
1138
|
+
|
|
1139
|
+
viewpointNode .setup ();
|
|
1140
|
+
|
|
1141
|
+
return viewpointNode;
|
|
1142
|
+
},
|
|
1143
|
+
nodesArray: function (nodes)
|
|
1144
|
+
{
|
|
1145
|
+
if (!(nodes instanceof Array))
|
|
1146
|
+
return;
|
|
1147
|
+
|
|
1148
|
+
this .nodes = nodes;
|
|
1149
|
+
},
|
|
1150
|
+
nodeObject: function (node)
|
|
1151
|
+
{
|
|
1152
|
+
if (!(node instanceof Object))
|
|
1153
|
+
return;
|
|
1154
|
+
|
|
1155
|
+
if (node .childNode !== undefined)
|
|
1156
|
+
return node .childNode;
|
|
1157
|
+
|
|
1158
|
+
// Create Transform or HAnimJoint.
|
|
1159
|
+
|
|
1160
|
+
const
|
|
1161
|
+
scene = this .getExecutionContext (),
|
|
1162
|
+
transformNode = scene .createNode ("Transform", false),
|
|
1163
|
+
name = this .sanitizeName (node .name);
|
|
1164
|
+
|
|
1165
|
+
// Name
|
|
1166
|
+
|
|
1167
|
+
if (name)
|
|
1168
|
+
scene .addNamedNode (scene .getUniqueName (name), transformNode);
|
|
1169
|
+
|
|
1170
|
+
// Set transformation matrix.
|
|
1171
|
+
|
|
1172
|
+
const
|
|
1173
|
+
translation = new Vector3 (0, 0, 0),
|
|
1174
|
+
quaternion = new Quaternion (0, 0, 0, 1),
|
|
1175
|
+
rotation = new Rotation4 (),
|
|
1176
|
+
scale = new Vector3 (1, 1, 1),
|
|
1177
|
+
scaleOrientation = new Rotation4 (),
|
|
1178
|
+
matrix = new Matrix4 ();
|
|
1179
|
+
|
|
1180
|
+
if (this .vectorValue (node .matrix, matrix))
|
|
1181
|
+
{
|
|
1182
|
+
matrix .get (translation, rotation, scale, scaleOrientation);
|
|
1183
|
+
|
|
1184
|
+
transformNode ._translation = translation;
|
|
1185
|
+
transformNode ._rotation = rotation;
|
|
1186
|
+
transformNode ._scale = scale;
|
|
1187
|
+
transformNode ._scaleOrientation = scaleOrientation;
|
|
1188
|
+
}
|
|
1189
|
+
else
|
|
1190
|
+
{
|
|
1191
|
+
if (this .vectorValue (node .translation, translation))
|
|
1192
|
+
transformNode ._translation = translation;
|
|
1193
|
+
|
|
1194
|
+
if (this .vectorValue (node .rotation, quaternion))
|
|
1195
|
+
transformNode ._rotation = new Rotation4 (quaternion);
|
|
1196
|
+
|
|
1197
|
+
if (this .vectorValue (node .scale, scale))
|
|
1198
|
+
transformNode ._scale = scale;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// Add camera.
|
|
1202
|
+
|
|
1203
|
+
const viewpointNode = this .cameraObject (this .cameras [node .camera]);
|
|
1204
|
+
|
|
1205
|
+
if (viewpointNode)
|
|
1206
|
+
transformNode ._children .push (viewpointNode);
|
|
1207
|
+
|
|
1208
|
+
// Add light.
|
|
1209
|
+
|
|
1210
|
+
this .nodeExtensions (node .extensions, transformNode);
|
|
1211
|
+
|
|
1212
|
+
// Add mesh.
|
|
1213
|
+
|
|
1214
|
+
const mesh = this .meshes [node .mesh];
|
|
1215
|
+
|
|
1216
|
+
if (mesh)
|
|
1217
|
+
transformNode ._children .push (... this .meshObject (mesh));
|
|
1218
|
+
|
|
1219
|
+
// Get children.
|
|
1220
|
+
|
|
1221
|
+
transformNode ._children .push (... this .nodeChildrenArray (node .children));
|
|
1222
|
+
|
|
1223
|
+
// Finish.
|
|
1224
|
+
|
|
1225
|
+
transformNode .setup ();
|
|
1226
|
+
|
|
1227
|
+
if (transformNode ._children .length === 0)
|
|
1228
|
+
return node .childNode = null;
|
|
1229
|
+
|
|
1230
|
+
return node .childNode = transformNode;
|
|
1231
|
+
},
|
|
1232
|
+
nodeExtensions: function (extensions, transformNode)
|
|
1233
|
+
{
|
|
1234
|
+
if (!(extensions instanceof Object))
|
|
1235
|
+
return;
|
|
1236
|
+
|
|
1237
|
+
this .nodeLight (extensions .KHR_lights_punctual, transformNode);
|
|
1238
|
+
},
|
|
1239
|
+
nodeLight: function (khrLightsPunctual, transformNode)
|
|
1240
|
+
{
|
|
1241
|
+
if (!(khrLightsPunctual instanceof Object))
|
|
1242
|
+
return;
|
|
1243
|
+
|
|
1244
|
+
const lightNode = this .lightObject (this .lights [khrLightsPunctual .light]);
|
|
1245
|
+
|
|
1246
|
+
if (!lightNode)
|
|
1247
|
+
return;
|
|
1248
|
+
|
|
1249
|
+
++ this .usedLights;
|
|
1250
|
+
|
|
1251
|
+
transformNode ._children .push (lightNode);
|
|
1252
|
+
},
|
|
1253
|
+
nodeChildrenArray: function (children)
|
|
1254
|
+
{
|
|
1255
|
+
if (!(children instanceof Array))
|
|
1256
|
+
return [ ];
|
|
1257
|
+
|
|
1258
|
+
return children
|
|
1259
|
+
.map (index => this .nodeObject (this .nodes [index], index))
|
|
1260
|
+
.filter (node => node);
|
|
1261
|
+
},
|
|
1262
|
+
scenesArray: function (scenes, sceneNumber)
|
|
1263
|
+
{
|
|
1264
|
+
if (!(scenes instanceof Array))
|
|
1265
|
+
return;
|
|
1266
|
+
|
|
1267
|
+
const
|
|
1268
|
+
scene = this .getExecutionContext (),
|
|
1269
|
+
children = scenes .map (scene => this .sceneObject (scene));
|
|
1270
|
+
|
|
1271
|
+
switch (children .length)
|
|
1272
|
+
{
|
|
1273
|
+
case 0:
|
|
1274
|
+
{
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
case 1:
|
|
1278
|
+
{
|
|
1279
|
+
if (sceneNumber === 0)
|
|
1280
|
+
{
|
|
1281
|
+
if (this .usedLights)
|
|
1282
|
+
scene .getRootNodes () .push (this .createNavigationInfo ());
|
|
1283
|
+
|
|
1284
|
+
scene .getRootNodes () .push (children [0]);
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// Proceed with next case:
|
|
1289
|
+
}
|
|
1290
|
+
default:
|
|
1291
|
+
{
|
|
1292
|
+
// Root
|
|
1293
|
+
|
|
1294
|
+
if (this .usedLights)
|
|
1295
|
+
scene .getRootNodes () .push (this .createNavigationInfo ());
|
|
1296
|
+
|
|
1297
|
+
const switchNode = scene .createNode ("Switch", false);
|
|
1298
|
+
|
|
1299
|
+
scene .addNamedNode (scene .getUniqueName ("Scenes"), switchNode);
|
|
1300
|
+
|
|
1301
|
+
// Scenes.
|
|
1302
|
+
|
|
1303
|
+
switchNode ._whichChoice = sceneNumber;
|
|
1304
|
+
switchNode ._children = children;
|
|
1305
|
+
|
|
1306
|
+
switchNode .setup ();
|
|
1307
|
+
|
|
1308
|
+
scene .getRootNodes () .push (switchNode);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
},
|
|
1313
|
+
sceneObject: function (sceneObject)
|
|
1314
|
+
{
|
|
1315
|
+
if (!(sceneObject instanceof Object))
|
|
1316
|
+
return null;
|
|
1317
|
+
|
|
1318
|
+
const nodes = this .sceneNodesArray (sceneObject .nodes);
|
|
1319
|
+
|
|
1320
|
+
switch (nodes .length)
|
|
1321
|
+
{
|
|
1322
|
+
case 0:
|
|
1323
|
+
{
|
|
1324
|
+
return null;
|
|
1325
|
+
}
|
|
1326
|
+
case 1:
|
|
1327
|
+
{
|
|
1328
|
+
return nodes [0];
|
|
1329
|
+
}
|
|
1330
|
+
default:
|
|
1331
|
+
{
|
|
1332
|
+
const
|
|
1333
|
+
scene = this .getExecutionContext (),
|
|
1334
|
+
groupNode = scene .createNode ("Group", false),
|
|
1335
|
+
name = this .sanitizeName (sceneObject .name);
|
|
1336
|
+
|
|
1337
|
+
if (name)
|
|
1338
|
+
scene .addNamedNode (scene .getUniqueName (name), groupNode);
|
|
1339
|
+
|
|
1340
|
+
groupNode ._children = nodes;
|
|
1341
|
+
|
|
1342
|
+
groupNode .setup ();
|
|
1343
|
+
|
|
1344
|
+
return groupNode;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
sceneNodesArray: function (nodes)
|
|
1349
|
+
{
|
|
1350
|
+
return this .nodeChildrenArray (nodes);
|
|
1351
|
+
},
|
|
1352
|
+
animationsArray: function (animations)
|
|
1353
|
+
{
|
|
1354
|
+
if (!(animations instanceof Array))
|
|
1355
|
+
return;
|
|
1356
|
+
|
|
1357
|
+
const animationNodes = animations
|
|
1358
|
+
.map (animation => this .animationObject (animation))
|
|
1359
|
+
.filter (node => node);
|
|
1360
|
+
|
|
1361
|
+
if (!animationNodes .length)
|
|
1362
|
+
return;
|
|
1363
|
+
|
|
1364
|
+
const
|
|
1365
|
+
scene = this .getExecutionContext (),
|
|
1366
|
+
groupNode = scene .createNode ("Group", false);
|
|
1367
|
+
|
|
1368
|
+
scene .addNamedNode (scene .getUniqueName ("Animations"), groupNode);
|
|
1369
|
+
scene .addExportedNode ("Animations", groupNode);
|
|
1370
|
+
|
|
1371
|
+
groupNode ._children = animationNodes;
|
|
1372
|
+
|
|
1373
|
+
groupNode .setup ();
|
|
1374
|
+
|
|
1375
|
+
scene .getRootNodes () .push (groupNode);
|
|
1376
|
+
},
|
|
1377
|
+
animationObject: function (animation)
|
|
1378
|
+
{
|
|
1379
|
+
if (!(animation instanceof Object))
|
|
1380
|
+
return null;
|
|
1381
|
+
|
|
1382
|
+
const
|
|
1383
|
+
scene = this .getExecutionContext (),
|
|
1384
|
+
timeSensorNode = scene .createNode ("TimeSensor", false),
|
|
1385
|
+
channelNodes = this .animationChannelsArray (animation .channels, animation .samplers, timeSensorNode);
|
|
1386
|
+
|
|
1387
|
+
if (!channelNodes .length)
|
|
1388
|
+
return null;
|
|
1389
|
+
|
|
1390
|
+
const
|
|
1391
|
+
groupNode = scene .createNode ("Group", false),
|
|
1392
|
+
name = this .sanitizeName (animation .name);
|
|
1393
|
+
|
|
1394
|
+
++ this .animations;
|
|
1395
|
+
|
|
1396
|
+
scene .addNamedNode (scene .getUniqueName (name || `Animation${this .animations}`), groupNode);
|
|
1397
|
+
scene .addNamedNode (scene .getUniqueName (`Timer${this .animations}`), timeSensorNode);
|
|
1398
|
+
|
|
1399
|
+
timeSensorNode ._description = animation .name || `Animation ${this .animations}`;
|
|
1400
|
+
groupNode ._children .push (timeSensorNode, ... channelNodes);
|
|
1401
|
+
|
|
1402
|
+
timeSensorNode .setup ();
|
|
1403
|
+
groupNode .setup ();
|
|
1404
|
+
|
|
1405
|
+
return groupNode;
|
|
1406
|
+
},
|
|
1407
|
+
animationChannelsArray: function (channels, samplers, timeSensorNode)
|
|
1408
|
+
{
|
|
1409
|
+
if (!(channels instanceof Array))
|
|
1410
|
+
return [ ];
|
|
1411
|
+
|
|
1412
|
+
if (!(samplers instanceof Array))
|
|
1413
|
+
return [ ];
|
|
1414
|
+
|
|
1415
|
+
const cycleInterval = samplers
|
|
1416
|
+
.map (sampler => this .accessors [sampler .input])
|
|
1417
|
+
.filter (input => input && input .array .length)
|
|
1418
|
+
.reduce ((value, input) => Math .max (value, input .array .at (-1)), 0);
|
|
1419
|
+
|
|
1420
|
+
timeSensorNode ._loop = DEBUG;
|
|
1421
|
+
timeSensorNode ._cycleInterval = cycleInterval;
|
|
1422
|
+
|
|
1423
|
+
return channels
|
|
1424
|
+
.map (channel => this .animationChannelObject (channel, samplers, timeSensorNode))
|
|
1425
|
+
.filter (node => node);
|
|
1426
|
+
},
|
|
1427
|
+
animationChannelObject: function (channel, samplers, timeSensorNode)
|
|
1428
|
+
{
|
|
1429
|
+
if (!(channel instanceof Object))
|
|
1430
|
+
return null;
|
|
1431
|
+
|
|
1432
|
+
const target = channel .target;
|
|
1433
|
+
|
|
1434
|
+
if (!(target instanceof Object))
|
|
1435
|
+
return null;
|
|
1436
|
+
|
|
1437
|
+
const node = this .nodeObject (this .nodes [target .node]);
|
|
1438
|
+
|
|
1439
|
+
if (!node)
|
|
1440
|
+
return null;
|
|
1441
|
+
|
|
1442
|
+
const sampler = samplers [channel .sampler];
|
|
1443
|
+
|
|
1444
|
+
if (!sampler)
|
|
1445
|
+
return null;
|
|
1446
|
+
|
|
1447
|
+
const input = this .accessors [sampler .input];
|
|
1448
|
+
|
|
1449
|
+
if (!input)
|
|
1450
|
+
return null;
|
|
1451
|
+
|
|
1452
|
+
if (!input .array .length)
|
|
1453
|
+
return null;
|
|
1454
|
+
|
|
1455
|
+
const output = this .accessors [sampler .output];
|
|
1456
|
+
|
|
1457
|
+
if (!output)
|
|
1458
|
+
return null;
|
|
1459
|
+
|
|
1460
|
+
if (!output .array .length)
|
|
1461
|
+
return null;
|
|
1462
|
+
|
|
1463
|
+
const
|
|
1464
|
+
scene = this .getExecutionContext (),
|
|
1465
|
+
interpolatorNode = this .createInterpolator (target .path, sampler .interpolation, input .array, output .array, timeSensorNode ._cycleInterval .getValue ());
|
|
1466
|
+
|
|
1467
|
+
if (!interpolatorNode)
|
|
1468
|
+
return null;
|
|
1469
|
+
|
|
1470
|
+
scene .addRoute (timeSensorNode, "fraction_changed", interpolatorNode, "set_fraction");
|
|
1471
|
+
scene .addRoute (interpolatorNode, "value_changed", node, target .path);
|
|
1472
|
+
|
|
1473
|
+
return interpolatorNode;
|
|
1474
|
+
},
|
|
1475
|
+
skinsArray: function (skins)
|
|
1476
|
+
{
|
|
1477
|
+
if (!(skins instanceof Array))
|
|
1478
|
+
return;
|
|
1479
|
+
},
|
|
1480
|
+
createNavigationInfo: function ()
|
|
1481
|
+
{
|
|
1482
|
+
const
|
|
1483
|
+
scene = this .getExecutionContext (),
|
|
1484
|
+
navigationInfoNode = scene .createNode ("NavigationInfo", false);
|
|
1485
|
+
|
|
1486
|
+
navigationInfoNode ._headlight = false;
|
|
1487
|
+
|
|
1488
|
+
navigationInfoNode .setup ();
|
|
1489
|
+
|
|
1490
|
+
return navigationInfoNode;
|
|
1491
|
+
},
|
|
1492
|
+
createShape: function (primitive)
|
|
1493
|
+
{
|
|
1494
|
+
const
|
|
1495
|
+
scene = this .getExecutionContext (),
|
|
1496
|
+
shapeNode = scene .createNode ("Shape", false),
|
|
1497
|
+
appearanceNode = this .materialObject (primitive .material),
|
|
1498
|
+
geometryNode = this .createGeometry (primitive);
|
|
1499
|
+
|
|
1500
|
+
shapeNode ._appearance = appearanceNode;
|
|
1501
|
+
shapeNode ._geometry = geometryNode;
|
|
1502
|
+
|
|
1503
|
+
shapeNode .setup ();
|
|
1504
|
+
|
|
1505
|
+
return shapeNode;
|
|
1506
|
+
},
|
|
1507
|
+
getDefaultAppearance: function ()
|
|
1508
|
+
{
|
|
1509
|
+
if (this .defaultAppearance)
|
|
1510
|
+
return this .defaultAppearance;
|
|
1511
|
+
|
|
1512
|
+
const
|
|
1513
|
+
scene = this .getExecutionContext (),
|
|
1514
|
+
appearanceNode = scene .createNode ("Appearance", false),
|
|
1515
|
+
materialNode = scene .createNode ("PhysicalMaterial", false);
|
|
1516
|
+
|
|
1517
|
+
appearanceNode ._alphaMode = "OPAQUE";
|
|
1518
|
+
appearanceNode ._material = materialNode;
|
|
1519
|
+
|
|
1520
|
+
materialNode .setup ();
|
|
1521
|
+
appearanceNode .setup ();
|
|
1522
|
+
|
|
1523
|
+
this .defaultAppearance = appearanceNode;
|
|
1524
|
+
|
|
1525
|
+
return appearanceNode;
|
|
1526
|
+
},
|
|
1527
|
+
createMultiTextureTransform: function (materialNode)
|
|
1528
|
+
{
|
|
1529
|
+
if (!+materialNode .getTextureBits ())
|
|
1530
|
+
return null;
|
|
1531
|
+
|
|
1532
|
+
const textureTransformNodes = [... this .textureTransformNodes .values ()]
|
|
1533
|
+
.sort ((a, b) => Algorithm .cmp (a ._mapping .getValue (), b ._mapping .getValue ()));
|
|
1534
|
+
|
|
1535
|
+
this .textureTransformNodes .clear ();
|
|
1536
|
+
|
|
1537
|
+
switch (textureTransformNodes .length)
|
|
1538
|
+
{
|
|
1539
|
+
case 0:
|
|
1540
|
+
{
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
case 1:
|
|
1544
|
+
{
|
|
1545
|
+
return textureTransformNodes [0];
|
|
1546
|
+
}
|
|
1547
|
+
default:
|
|
1548
|
+
{
|
|
1549
|
+
const
|
|
1550
|
+
scene = this .getExecutionContext (),
|
|
1551
|
+
textureTransformNode = scene .createNode ("MultiTextureTransform", false);
|
|
1552
|
+
|
|
1553
|
+
textureTransformNode ._textureTransform = textureTransformNodes;
|
|
1554
|
+
|
|
1555
|
+
textureTransformNode .setup ();
|
|
1556
|
+
|
|
1557
|
+
return textureTransformNode;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
},
|
|
1561
|
+
createGeometry: function (primitive)
|
|
1562
|
+
{
|
|
1563
|
+
switch (primitive .mode)
|
|
1564
|
+
{
|
|
1565
|
+
case 0: // POINTS
|
|
1566
|
+
{
|
|
1567
|
+
return this .createPointSet (primitive);
|
|
1568
|
+
}
|
|
1569
|
+
case 1: // LINES
|
|
1570
|
+
{
|
|
1571
|
+
if (primitive .indices)
|
|
1572
|
+
return this .createIndexedLineSet (primitive, 1);
|
|
1573
|
+
|
|
1574
|
+
return this .createLineSet (primitive);
|
|
1575
|
+
}
|
|
1576
|
+
case 2: // LINE_LOOP
|
|
1577
|
+
{
|
|
1578
|
+
return this .createIndexedLineSet (primitive, 2);
|
|
1579
|
+
}
|
|
1580
|
+
case 3: // LINE_STRIP
|
|
1581
|
+
{
|
|
1582
|
+
return this .createIndexedLineSet (primitive, 3);
|
|
1583
|
+
}
|
|
1584
|
+
default:
|
|
1585
|
+
case 4: // TRIANGLES
|
|
1586
|
+
{
|
|
1587
|
+
if (primitive .indices)
|
|
1588
|
+
return this .createIndexedTriangleSet (primitive);
|
|
1589
|
+
|
|
1590
|
+
return this .createTriangleSet (primitive);
|
|
1591
|
+
}
|
|
1592
|
+
case 5: // TRIANGLE_STRIP
|
|
1593
|
+
{
|
|
1594
|
+
if (primitive .indices)
|
|
1595
|
+
return this .createIndexedTriangleStripSet (primitive);
|
|
1596
|
+
|
|
1597
|
+
return this .createTriangleStripSet (primitive);
|
|
1598
|
+
}
|
|
1599
|
+
case 6: // TRIANGLE_FAN
|
|
1600
|
+
{
|
|
1601
|
+
if (primitive .indices)
|
|
1602
|
+
return this .createIndexedTriangleFanSet (primitive);
|
|
1603
|
+
|
|
1604
|
+
return this .createTriangleFanSet (primitive);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
},
|
|
1608
|
+
createPointSet: function ({ attributes, material })
|
|
1609
|
+
{
|
|
1610
|
+
const
|
|
1611
|
+
scene = this .getExecutionContext (),
|
|
1612
|
+
geometryNode = scene .createNode ("PointSet", false);
|
|
1613
|
+
|
|
1614
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1615
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1616
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1617
|
+
|
|
1618
|
+
geometryNode .setup ();
|
|
1619
|
+
|
|
1620
|
+
return geometryNode;
|
|
1621
|
+
},
|
|
1622
|
+
createIndexedLineSet: function ({ attributes, indices, material }, mode)
|
|
1623
|
+
{
|
|
1624
|
+
const
|
|
1625
|
+
scene = this .getExecutionContext (),
|
|
1626
|
+
geometryNode = scene .createNode ("IndexedLineSet", false);
|
|
1627
|
+
|
|
1628
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1629
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1630
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1631
|
+
|
|
1632
|
+
switch (mode)
|
|
1633
|
+
{
|
|
1634
|
+
case 1: // LINES
|
|
1635
|
+
{
|
|
1636
|
+
const
|
|
1637
|
+
coordIndex = geometryNode ._coordIndex,
|
|
1638
|
+
array = indices .array,
|
|
1639
|
+
length = array .length;
|
|
1640
|
+
|
|
1641
|
+
for (let i = 0; i < length; i += 2)
|
|
1642
|
+
coordIndex .push (array [i], array [i + 1], -1);
|
|
1643
|
+
|
|
1644
|
+
break
|
|
1645
|
+
}
|
|
1646
|
+
case 2: // LINE_LOOP
|
|
1647
|
+
{
|
|
1648
|
+
const coordIndex = geometryNode ._coordIndex;
|
|
1649
|
+
|
|
1650
|
+
if (indices)
|
|
1651
|
+
{
|
|
1652
|
+
coordIndex .push (... indices .array);
|
|
1653
|
+
|
|
1654
|
+
if (coordIndex .length)
|
|
1655
|
+
coordIndex .push (coordIndex [0], -1);
|
|
1656
|
+
}
|
|
1657
|
+
else
|
|
1658
|
+
{
|
|
1659
|
+
const coord = geometryNode ._coord;
|
|
1660
|
+
|
|
1661
|
+
if (coord && coord .point .length)
|
|
1662
|
+
coordIndex .push (... coord .point .keys (), 0, -1);
|
|
1663
|
+
}
|
|
1664
|
+
break
|
|
1665
|
+
}
|
|
1666
|
+
case 3: // LINE_STRIP
|
|
1667
|
+
{
|
|
1668
|
+
const coordIndex = geometryNode ._coordIndex;
|
|
1669
|
+
|
|
1670
|
+
if (indices)
|
|
1671
|
+
{
|
|
1672
|
+
coordIndex .push (... indices .array);
|
|
1673
|
+
|
|
1674
|
+
if (coordIndex .length)
|
|
1675
|
+
coordIndex .push (-1);
|
|
1676
|
+
}
|
|
1677
|
+
else
|
|
1678
|
+
{
|
|
1679
|
+
const coord = geometryNode ._coord;
|
|
1680
|
+
|
|
1681
|
+
if (coord && coord .point .length)
|
|
1682
|
+
coordIndex .push (... coord .point .keys (), -1);
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
break
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
geometryNode .setup ();
|
|
1690
|
+
|
|
1691
|
+
return geometryNode;
|
|
1692
|
+
},
|
|
1693
|
+
createLineSet: function ({ attributes, material })
|
|
1694
|
+
{
|
|
1695
|
+
const
|
|
1696
|
+
scene = this .getExecutionContext (),
|
|
1697
|
+
geometryNode = scene .createNode ("LineSet", false);
|
|
1698
|
+
|
|
1699
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1700
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1701
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1702
|
+
|
|
1703
|
+
geometryNode .setup ();
|
|
1704
|
+
|
|
1705
|
+
return geometryNode;
|
|
1706
|
+
},
|
|
1707
|
+
createIndexedTriangleSet: function ({ attributes, indices, material })
|
|
1708
|
+
{
|
|
1709
|
+
const
|
|
1710
|
+
scene = this .getExecutionContext (),
|
|
1711
|
+
geometryNode = scene .createNode ("IndexedTriangleSet", false);
|
|
1712
|
+
|
|
1713
|
+
geometryNode ._solid = material ? ! material .doubleSided : true;
|
|
1714
|
+
geometryNode ._index = indices .array;
|
|
1715
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1716
|
+
geometryNode ._texCoord = this .createMultiTextureCoordinate (attributes .TEXCOORD, material);
|
|
1717
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1718
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1719
|
+
geometryNode ._normalPerVertex = !! geometryNode ._normal;
|
|
1720
|
+
|
|
1721
|
+
geometryNode .setup ();
|
|
1722
|
+
|
|
1723
|
+
return geometryNode;
|
|
1724
|
+
},
|
|
1725
|
+
createTriangleSet: function ({ attributes, material })
|
|
1726
|
+
{
|
|
1727
|
+
const
|
|
1728
|
+
scene = this .getExecutionContext (),
|
|
1729
|
+
geometryNode = scene .createNode ("TriangleSet", false);
|
|
1730
|
+
|
|
1731
|
+
geometryNode ._solid = material ? ! material .doubleSided : true;
|
|
1732
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1733
|
+
geometryNode ._texCoord = this .createMultiTextureCoordinate (attributes .TEXCOORD, material);
|
|
1734
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1735
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1736
|
+
geometryNode ._normalPerVertex = !! geometryNode ._normal;
|
|
1737
|
+
|
|
1738
|
+
geometryNode .setup ();
|
|
1739
|
+
|
|
1740
|
+
return geometryNode;
|
|
1741
|
+
},
|
|
1742
|
+
createIndexedTriangleStripSet: function ({ attributes, indices, material })
|
|
1743
|
+
{
|
|
1744
|
+
const
|
|
1745
|
+
scene = this .getExecutionContext (),
|
|
1746
|
+
geometryNode = scene .createNode ("IndexedTriangleStripSet", false);
|
|
1747
|
+
|
|
1748
|
+
geometryNode ._solid = material ? ! material .doubleSided : true;
|
|
1749
|
+
geometryNode ._index = indices .array;
|
|
1750
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1751
|
+
geometryNode ._texCoord = this .createMultiTextureCoordinate (attributes .TEXCOORD, material);
|
|
1752
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1753
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1754
|
+
geometryNode ._normalPerVertex = !! geometryNode ._normal;
|
|
1755
|
+
|
|
1756
|
+
geometryNode .setup ();
|
|
1757
|
+
|
|
1758
|
+
return geometryNode;
|
|
1759
|
+
},
|
|
1760
|
+
createTriangleStripSet: function ({ attributes, material })
|
|
1761
|
+
{
|
|
1762
|
+
const
|
|
1763
|
+
scene = this .getExecutionContext (),
|
|
1764
|
+
geometryNode = scene .createNode ("TriangleStripSet", false);
|
|
1765
|
+
|
|
1766
|
+
geometryNode ._solid = material ? ! material .doubleSided : true;
|
|
1767
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1768
|
+
geometryNode ._texCoord = this .createMultiTextureCoordinate (attributes .TEXCOORD, material);
|
|
1769
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1770
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1771
|
+
geometryNode ._normalPerVertex = !! geometryNode ._normal;
|
|
1772
|
+
|
|
1773
|
+
const coord = geometryNode ._coord;
|
|
1774
|
+
|
|
1775
|
+
if (coord)
|
|
1776
|
+
{
|
|
1777
|
+
if (coord .point .length)
|
|
1778
|
+
geometryNode ._stripCount = [coord .point .length];
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
geometryNode .setup ();
|
|
1782
|
+
|
|
1783
|
+
return geometryNode;
|
|
1784
|
+
},
|
|
1785
|
+
createIndexedTriangleFanSet: function ({ attributes, indices, material })
|
|
1786
|
+
{
|
|
1787
|
+
const
|
|
1788
|
+
scene = this .getExecutionContext (),
|
|
1789
|
+
geometryNode = scene .createNode ("IndexedTriangleFanSet", false);
|
|
1790
|
+
|
|
1791
|
+
geometryNode ._solid = material ? ! material .doubleSided : true;
|
|
1792
|
+
geometryNode ._index = indices .array;
|
|
1793
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1794
|
+
geometryNode ._texCoord = this .createMultiTextureCoordinate (attributes .TEXCOORD, material);
|
|
1795
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1796
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1797
|
+
geometryNode ._normalPerVertex = !! geometryNode ._normal;
|
|
1798
|
+
|
|
1799
|
+
geometryNode .setup ();
|
|
1800
|
+
|
|
1801
|
+
return geometryNode;
|
|
1802
|
+
},
|
|
1803
|
+
createTriangleFanSet: function ({ attributes, material })
|
|
1804
|
+
{
|
|
1805
|
+
const
|
|
1806
|
+
scene = this .getExecutionContext (),
|
|
1807
|
+
geometryNode = scene .createNode ("TriangleFanSet", false);
|
|
1808
|
+
|
|
1809
|
+
geometryNode ._solid = material ? ! material .doubleSided : true;
|
|
1810
|
+
geometryNode ._color = this .createColor (attributes .COLOR [0], material);
|
|
1811
|
+
geometryNode ._texCoord = this .createMultiTextureCoordinate (attributes .TEXCOORD, material);
|
|
1812
|
+
geometryNode ._normal = this .createNormal (attributes .NORMAL);
|
|
1813
|
+
geometryNode ._coord = this .createCoordinate (attributes .POSITION);
|
|
1814
|
+
geometryNode ._normalPerVertex = !! geometryNode ._normal;
|
|
1815
|
+
|
|
1816
|
+
const coord = geometryNode ._coord;
|
|
1817
|
+
|
|
1818
|
+
if (coord)
|
|
1819
|
+
{
|
|
1820
|
+
if (coord .point .length)
|
|
1821
|
+
geometryNode ._fanCount = [coord .point .length];
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
geometryNode .setup ();
|
|
1825
|
+
|
|
1826
|
+
return geometryNode;
|
|
1827
|
+
},
|
|
1828
|
+
createColor: (function ()
|
|
1829
|
+
{
|
|
1830
|
+
const TypeNames = new Map ([
|
|
1831
|
+
["VEC3", "Color"],
|
|
1832
|
+
["VEC4", "ColorRGBA"],
|
|
1833
|
+
]);
|
|
1834
|
+
|
|
1835
|
+
return function (color, material)
|
|
1836
|
+
{
|
|
1837
|
+
if (!(color instanceof Object))
|
|
1838
|
+
return null;
|
|
1839
|
+
|
|
1840
|
+
const typeName = TypeNames .get (color .type);
|
|
1841
|
+
|
|
1842
|
+
if (!typeName)
|
|
1843
|
+
return null;
|
|
1844
|
+
|
|
1845
|
+
if (color .colorNode)
|
|
1846
|
+
return color .colorNode;
|
|
1847
|
+
|
|
1848
|
+
const
|
|
1849
|
+
scene = this .getExecutionContext (),
|
|
1850
|
+
appearanceNode = this .materialObject (material),
|
|
1851
|
+
opaque = appearanceNode ._alphaMode .getValue () === "OPAQUE",
|
|
1852
|
+
colorNode = scene .createNode (opaque ? "Color" : typeName, false);
|
|
1853
|
+
|
|
1854
|
+
colorNode ._color = opaque && typeName !== "Color"
|
|
1855
|
+
? color .array .filter ((_, i) => (i + 1) % 4)
|
|
1856
|
+
: color .array;
|
|
1857
|
+
|
|
1858
|
+
colorNode .setup ();
|
|
1859
|
+
|
|
1860
|
+
return color .colorNode = colorNode;
|
|
1861
|
+
};
|
|
1862
|
+
})(),
|
|
1863
|
+
createMultiTextureCoordinate: function (texCoords, material)
|
|
1864
|
+
{
|
|
1865
|
+
const appearanceNode = this .materialObject (material);
|
|
1866
|
+
|
|
1867
|
+
if (!+appearanceNode ._material .getValue () .getTextureBits ())
|
|
1868
|
+
return null;
|
|
1869
|
+
|
|
1870
|
+
if (texCoords .textureCoordinateNode)
|
|
1871
|
+
return texCoords .textureCoordinateNode;
|
|
1872
|
+
|
|
1873
|
+
switch (texCoords .length)
|
|
1874
|
+
{
|
|
1875
|
+
case 0:
|
|
1876
|
+
{
|
|
1877
|
+
return null;
|
|
1878
|
+
}
|
|
1879
|
+
case 1:
|
|
1880
|
+
{
|
|
1881
|
+
return texCoords .textureCoordinateNode = this .createTextureCoordinate (texCoords [0], 0);
|
|
1882
|
+
}
|
|
1883
|
+
default:
|
|
1884
|
+
{
|
|
1885
|
+
const textureCoordinateNodes = texCoords
|
|
1886
|
+
.map ((texCoord, i) => this .createTextureCoordinate (texCoord, i))
|
|
1887
|
+
.filter (node => node)
|
|
1888
|
+
.sort ((a, b) => Algorithm .cmp (a ._mapping .getValue (), b ._mapping .getValue ()));
|
|
1889
|
+
|
|
1890
|
+
if (!textureCoordinateNodes .length)
|
|
1891
|
+
return null;
|
|
1892
|
+
|
|
1893
|
+
const
|
|
1894
|
+
scene = this .getExecutionContext (),
|
|
1895
|
+
textureCoordinateNode = scene .createNode ("MultiTextureCoordinate", false);
|
|
1896
|
+
|
|
1897
|
+
textureCoordinateNode ._texCoord = textureCoordinateNodes;
|
|
1898
|
+
|
|
1899
|
+
textureCoordinateNode .setup ();
|
|
1900
|
+
|
|
1901
|
+
return texCoords .textureCoordinateNode = textureCoordinateNode;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
},
|
|
1905
|
+
createTextureCoordinate: function (texCoord, mapping)
|
|
1906
|
+
{
|
|
1907
|
+
if (!(texCoord instanceof Object))
|
|
1908
|
+
return null;
|
|
1909
|
+
|
|
1910
|
+
if (texCoord .type !== "VEC2")
|
|
1911
|
+
return null;
|
|
1912
|
+
|
|
1913
|
+
if (texCoord .textureCoordinateNode)
|
|
1914
|
+
return texCoord .textureCoordinateNode;
|
|
1915
|
+
|
|
1916
|
+
const
|
|
1917
|
+
scene = this .getExecutionContext (),
|
|
1918
|
+
textureCoordinateNode = scene .createNode ("TextureCoordinate", false);
|
|
1919
|
+
|
|
1920
|
+
textureCoordinateNode ._mapping = "TEXCOORD_" + mapping;
|
|
1921
|
+
textureCoordinateNode ._point = texCoord .array;
|
|
1922
|
+
|
|
1923
|
+
textureCoordinateNode .setup ();
|
|
1924
|
+
|
|
1925
|
+
return texCoord .textureCoordinateNode = textureCoordinateNode;
|
|
1926
|
+
},
|
|
1927
|
+
createNormal: function (normal)
|
|
1928
|
+
{
|
|
1929
|
+
if (!(normal instanceof Object))
|
|
1930
|
+
return null;
|
|
1931
|
+
|
|
1932
|
+
if (normal .type !== "VEC3")
|
|
1933
|
+
return null;
|
|
1934
|
+
|
|
1935
|
+
if (normal .normalNode)
|
|
1936
|
+
return normal .normalNode;
|
|
1937
|
+
|
|
1938
|
+
const
|
|
1939
|
+
scene = this .getExecutionContext (),
|
|
1940
|
+
normalNode = scene .createNode ("Normal", false);
|
|
1941
|
+
|
|
1942
|
+
normalNode ._vector = normal .array;
|
|
1943
|
+
|
|
1944
|
+
normalNode .setup ();
|
|
1945
|
+
|
|
1946
|
+
return normal .normalNode = normalNode;
|
|
1947
|
+
},
|
|
1948
|
+
createCoordinate: function (position)
|
|
1949
|
+
{
|
|
1950
|
+
if (!(position instanceof Object))
|
|
1951
|
+
return null;
|
|
1952
|
+
|
|
1953
|
+
if (position .type !== "VEC3")
|
|
1954
|
+
return null;
|
|
1955
|
+
|
|
1956
|
+
if (position .coordinateNode)
|
|
1957
|
+
return position .coordinateNode;
|
|
1958
|
+
|
|
1959
|
+
const
|
|
1960
|
+
scene = this .getExecutionContext (),
|
|
1961
|
+
coordinateNode = scene .createNode ("Coordinate", false);
|
|
1962
|
+
|
|
1963
|
+
coordinateNode ._point = position .array;
|
|
1964
|
+
|
|
1965
|
+
coordinateNode .setup ();
|
|
1966
|
+
|
|
1967
|
+
return position .coordinateNode = coordinateNode;
|
|
1968
|
+
},
|
|
1969
|
+
createInterpolator: function (path, interpolation, times, keyValues, cycleInterval)
|
|
1970
|
+
{
|
|
1971
|
+
const scene = this .getExecutionContext ();
|
|
1972
|
+
|
|
1973
|
+
switch (path)
|
|
1974
|
+
{
|
|
1975
|
+
case "translation":
|
|
1976
|
+
{
|
|
1977
|
+
const interpolatorNode = this .createPositionInterpolator (interpolation, times, keyValues, cycleInterval);
|
|
1978
|
+
|
|
1979
|
+
scene .addNamedNode (scene .getUniqueName ("TranslationInterpolator"), interpolatorNode);
|
|
1980
|
+
|
|
1981
|
+
return interpolatorNode;
|
|
1982
|
+
}
|
|
1983
|
+
case "rotation":
|
|
1984
|
+
{
|
|
1985
|
+
const interpolatorNode = this .createOrientationInterpolator (interpolation, times, keyValues, cycleInterval);
|
|
1986
|
+
|
|
1987
|
+
scene .addNamedNode (scene .getUniqueName ("RotationInterpolator"), interpolatorNode);
|
|
1988
|
+
|
|
1989
|
+
return interpolatorNode;
|
|
1990
|
+
}
|
|
1991
|
+
case "scale":
|
|
1992
|
+
{
|
|
1993
|
+
const interpolatorNode = this .createPositionInterpolator (interpolation, times, keyValues, cycleInterval);
|
|
1994
|
+
|
|
1995
|
+
scene .addNamedNode (scene .getUniqueName ("ScaleInterpolator"), interpolatorNode);
|
|
1996
|
+
|
|
1997
|
+
return interpolatorNode;
|
|
1998
|
+
}
|
|
1999
|
+
case "weights":
|
|
2000
|
+
default:
|
|
2001
|
+
{
|
|
2002
|
+
return null;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
},
|
|
2006
|
+
createPositionInterpolator: function (interpolation, times, keyValues, cycleInterval)
|
|
2007
|
+
{
|
|
2008
|
+
const scene = this .getExecutionContext ();
|
|
2009
|
+
|
|
2010
|
+
switch (interpolation)
|
|
2011
|
+
{
|
|
2012
|
+
case "STEP":
|
|
2013
|
+
{
|
|
2014
|
+
const interpolatorNode = scene .createNode ("PositionInterpolator", false);
|
|
2015
|
+
|
|
2016
|
+
// Key
|
|
2017
|
+
|
|
2018
|
+
interpolatorNode ._key .push (times [0] / cycleInterval);
|
|
2019
|
+
|
|
2020
|
+
for (let i = 1, length = times .length; i < length; ++ i)
|
|
2021
|
+
interpolatorNode ._key .push ((times [i] - STEP_TIME) / cycleInterval, times [i] / cycleInterval);
|
|
2022
|
+
|
|
2023
|
+
// KeyValue
|
|
2024
|
+
|
|
2025
|
+
interpolatorNode ._keyValue .push (new Vector3 (keyValues [0], keyValues [1], keyValues [2]));
|
|
2026
|
+
|
|
2027
|
+
for (let i = 0, length = keyValues .length - 3; i < length; i += 3)
|
|
2028
|
+
{
|
|
2029
|
+
interpolatorNode ._keyValue .push (new Vector3 (keyValues [i + 0], keyValues [i + 1], keyValues [i + 2]),
|
|
2030
|
+
new Vector3 (keyValues [i + 3], keyValues [i + 4], keyValues [i + 5]));
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
// Finish
|
|
2034
|
+
|
|
2035
|
+
interpolatorNode .setup ();
|
|
2036
|
+
|
|
2037
|
+
return interpolatorNode;
|
|
2038
|
+
}
|
|
2039
|
+
default:
|
|
2040
|
+
case "LINEAR":
|
|
2041
|
+
{
|
|
2042
|
+
const interpolatorNode = scene .createNode ("PositionInterpolator", false);
|
|
2043
|
+
|
|
2044
|
+
interpolatorNode ._key = times .map (t => t / cycleInterval);
|
|
2045
|
+
interpolatorNode ._keyValue = keyValues;
|
|
2046
|
+
|
|
2047
|
+
interpolatorNode .setup ();
|
|
2048
|
+
|
|
2049
|
+
return interpolatorNode;
|
|
2050
|
+
}
|
|
2051
|
+
case "CUBICSPLINE":
|
|
2052
|
+
{
|
|
2053
|
+
const
|
|
2054
|
+
interpolatorNode = scene .createNode ("PositionInterpolator", false),
|
|
2055
|
+
vectors = [ ];
|
|
2056
|
+
|
|
2057
|
+
for (let i = 0, length = keyValues .length; i < length; i += 3)
|
|
2058
|
+
{
|
|
2059
|
+
vectors .push (new Vector3 (keyValues [i + 0],
|
|
2060
|
+
keyValues [i + 1],
|
|
2061
|
+
keyValues [i + 2]));
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
const samples = [... Array (Math .floor (times .at (-1) * SAMPLES_PER_SECOND)) .keys ()]
|
|
2065
|
+
.map ((_, i, array) => i / (array .length - 1) * times .at (-1));
|
|
2066
|
+
|
|
2067
|
+
for (const t of samples)
|
|
2068
|
+
{
|
|
2069
|
+
interpolatorNode ._key .push (t / cycleInterval);
|
|
2070
|
+
interpolatorNode ._keyValue .push (this .cubicSpline (t, times, vectors));
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
interpolatorNode .setup ();
|
|
2074
|
+
|
|
2075
|
+
return interpolatorNode;
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
}
|
|
2079
|
+
},
|
|
2080
|
+
createOrientationInterpolator: function (interpolation, times, keyValues, cycleInterval)
|
|
2081
|
+
{
|
|
2082
|
+
const scene = this .getExecutionContext ();
|
|
2083
|
+
|
|
2084
|
+
switch (interpolation)
|
|
2085
|
+
{
|
|
2086
|
+
case "STEP":
|
|
2087
|
+
{
|
|
2088
|
+
const interpolatorNode = scene .createNode ("OrientationInterpolator", false);
|
|
2089
|
+
|
|
2090
|
+
// Key
|
|
2091
|
+
|
|
2092
|
+
interpolatorNode ._key .push (times [0] / cycleInterval);
|
|
2093
|
+
|
|
2094
|
+
for (let i = 1, length = times .length; i < length; ++ i)
|
|
2095
|
+
interpolatorNode ._key .push ((times [i] - STEP_TIME) / cycleInterval, times [i] / cycleInterval);
|
|
2096
|
+
|
|
2097
|
+
// KeyValue
|
|
2098
|
+
|
|
2099
|
+
interpolatorNode ._keyValue .push (new Rotation4 (new Quaternion (keyValues [0],
|
|
2100
|
+
keyValues [1],
|
|
2101
|
+
keyValues [2],
|
|
2102
|
+
keyValues [3])));
|
|
2103
|
+
|
|
2104
|
+
for (let i = 0, length = keyValues .length - 4; i < length; i += 4)
|
|
2105
|
+
{
|
|
2106
|
+
interpolatorNode ._keyValue .push (new Rotation4 (new Quaternion (keyValues [i + 0],
|
|
2107
|
+
keyValues [i + 1],
|
|
2108
|
+
keyValues [i + 2],
|
|
2109
|
+
keyValues [i + 3])),
|
|
2110
|
+
new Rotation4 (new Quaternion (keyValues [i + 4],
|
|
2111
|
+
keyValues [i + 5],
|
|
2112
|
+
keyValues [i + 6],
|
|
2113
|
+
keyValues [i + 7])));
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
// Finish
|
|
2117
|
+
|
|
2118
|
+
interpolatorNode .setup ();
|
|
2119
|
+
|
|
2120
|
+
return interpolatorNode;
|
|
2121
|
+
}
|
|
2122
|
+
default:
|
|
2123
|
+
case "LINEAR":
|
|
2124
|
+
{
|
|
2125
|
+
const interpolatorNode = scene .createNode ("OrientationInterpolator", false);
|
|
2126
|
+
|
|
2127
|
+
interpolatorNode ._key = times .map (t => t / cycleInterval);
|
|
2128
|
+
|
|
2129
|
+
for (let i = 0, length = keyValues .length; i < length; i += 4)
|
|
2130
|
+
{
|
|
2131
|
+
interpolatorNode ._keyValue .push (new Rotation4 (new Quaternion (keyValues [i + 0],
|
|
2132
|
+
keyValues [i + 1],
|
|
2133
|
+
keyValues [i + 2],
|
|
2134
|
+
keyValues [i + 3])));
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
interpolatorNode .setup ();
|
|
2138
|
+
|
|
2139
|
+
return interpolatorNode;
|
|
2140
|
+
}
|
|
2141
|
+
case "CUBICSPLINE":
|
|
2142
|
+
{
|
|
2143
|
+
const
|
|
2144
|
+
interpolatorNode = scene .createNode ("OrientationInterpolator", false),
|
|
2145
|
+
quaternions = [ ];
|
|
2146
|
+
|
|
2147
|
+
for (let i = 0, length = keyValues .length; i < length; i += 4)
|
|
2148
|
+
{
|
|
2149
|
+
quaternions .push (new Quaternion (keyValues [i + 0],
|
|
2150
|
+
keyValues [i + 1],
|
|
2151
|
+
keyValues [i + 2],
|
|
2152
|
+
keyValues [i + 3]));
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
const samples = [... Array (Math .floor (times .at (-1) * SAMPLES_PER_SECOND)) .keys ()]
|
|
2156
|
+
.map ((_, i, array) => i / (array .length - 1) * times .at (-1));
|
|
2157
|
+
|
|
2158
|
+
for (const t of samples)
|
|
2159
|
+
{
|
|
2160
|
+
const q = this .cubicSpline (t, times, quaternions) .normalize ();
|
|
2161
|
+
|
|
2162
|
+
interpolatorNode ._key .push (t / cycleInterval);
|
|
2163
|
+
interpolatorNode ._keyValue .push (new Rotation4 (q));
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
interpolatorNode .setup ();
|
|
2167
|
+
|
|
2168
|
+
return interpolatorNode;
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
},
|
|
2172
|
+
cubicSpline: function (time, times, values)
|
|
2173
|
+
{
|
|
2174
|
+
const
|
|
2175
|
+
index1 = Algorithm .clamp (Algorithm .upperBound (times, 0, times .length, time), 1, times .length - 1),
|
|
2176
|
+
index0 = index1 - 1,
|
|
2177
|
+
td = times [index1] - times [index0],
|
|
2178
|
+
t = (time - times [index0]) / td,
|
|
2179
|
+
t2 = Math .pow (t, 2),
|
|
2180
|
+
t3 = Math .pow (t, 3),
|
|
2181
|
+
v0 = values [index0 * 3 + 1] .copy (),
|
|
2182
|
+
b0 = values [index0 * 3 + 2] .copy (),
|
|
2183
|
+
v1 = values [index1 * 3 + 1] .copy (),
|
|
2184
|
+
a1 = values [index1 * 3 + 0] .copy ();
|
|
2185
|
+
|
|
2186
|
+
v0 .multiply (2 * t3 - 3 * t2 + 1);
|
|
2187
|
+
b0 .multiply (td * (t3 - 2 * t2 + t));
|
|
2188
|
+
v1 .multiply (-2 * t3 + 3 * t2);
|
|
2189
|
+
a1 .multiply (td * (t3 - t2));
|
|
2190
|
+
|
|
2191
|
+
return v0 .add (b0) .add (v1) .add (a1);
|
|
2192
|
+
},
|
|
2193
|
+
vectorValue: function (array, vector)
|
|
2194
|
+
{
|
|
2195
|
+
if (!(array instanceof Array))
|
|
2196
|
+
return false;
|
|
2197
|
+
|
|
2198
|
+
if (array .length !== vector .length)
|
|
2199
|
+
return false;
|
|
2200
|
+
|
|
2201
|
+
vector .set (... array);
|
|
2202
|
+
|
|
2203
|
+
return true;
|
|
2204
|
+
},
|
|
2205
|
+
numberValue: function (value, defaultValue)
|
|
2206
|
+
{
|
|
2207
|
+
if (typeof value !== "number")
|
|
2208
|
+
return defaultValue;
|
|
2209
|
+
|
|
2210
|
+
return value;
|
|
2211
|
+
},
|
|
2212
|
+
stringValue: function (value, defaultValue)
|
|
2213
|
+
{
|
|
2214
|
+
if (typeof value !== "string")
|
|
2215
|
+
return defaultValue;
|
|
2216
|
+
|
|
2217
|
+
return value;
|
|
2218
|
+
},
|
|
2219
|
+
});
|
|
2220
|
+
|
|
2221
|
+
export default GLTF2Parser;
|