@woosh/meep-engine 2.106.0 → 2.107.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/meep.cjs +2310 -2529
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +2310 -2529
- package/editor/Editor.js +55 -60
- package/editor/SelectionVisualizer.js +111 -109
- package/editor/actions/concrete/ComponentAddAction.js +0 -3
- package/editor/actions/concrete/ComponentRemoveAction.js +0 -4
- package/editor/actions/concrete/EntityCreateAction.js +0 -3
- package/editor/actions/concrete/EntityRemoveAction.js +0 -4
- package/editor/actions/concrete/SelectionAddAction.js +0 -3
- package/editor/actions/concrete/SelectionClearAction.js +0 -3
- package/editor/actions/concrete/SelectionRemoveAction.js +0 -3
- package/editor/ecs/EditorEntity.js +8 -6
- package/editor/tools/SelectionTool.js +0 -5
- package/editor/tools/TopDownCameraControlTool.js +2 -5
- package/editor/tools/TransformTool.js +137 -136
- package/editor/tools/engine/Tool.js +1 -6
- package/editor/tools/engine/ToolEngine.js +145 -148
- package/editor/tools/v2/TransformControls.js +25 -24
- package/editor/view/EditorView.js +0 -5
- package/editor/view/ecs/ComponentControlFactory.js +37 -40
- package/editor/view/ecs/EntityEditor.js +0 -3
- package/editor/view/ecs/EntityList.js +6 -11
- package/editor/view/ecs/components/MeshController.js +4 -7
- package/editor/view/ecs/components/TransformController.js +3 -9
- package/editor/view/tools/ToolView.js +2 -8
- package/package.json +1 -1
- package/src/core/IdPool.d.ts.map +1 -1
- package/src/core/IdPool.js +0 -5
- package/src/core/UUID.d.ts.map +1 -1
- package/src/core/UUID.js +0 -4
- package/src/core/binary/BitSet.d.ts +17 -14
- package/src/core/binary/BitSet.d.ts.map +1 -1
- package/src/core/binary/BitSet.js +411 -412
- package/src/core/binary/type/Field.d.ts +0 -8
- package/src/core/binary/type/Field.d.ts.map +1 -1
- package/src/core/binary/type/Field.js +16 -19
- package/src/core/binary/type/MultiplicityType.js +0 -4
- package/src/core/binary/type/PrimitiveTypes.d.ts.map +1 -1
- package/src/core/binary/type/PrimitiveTypes.js +0 -4
- package/src/core/binary/type/Type.d.ts +0 -6
- package/src/core/binary/type/Type.d.ts.map +1 -1
- package/src/core/binary/type/Type.js +63 -64
- package/src/core/binary/type/TypeBuilder.d.ts +0 -1
- package/src/core/binary/type/TypeBuilder.d.ts.map +1 -1
- package/src/core/binary/type/TypeBuilder.js +15 -18
- package/src/core/binary/type/TypeRegistry.d.ts +6 -4
- package/src/core/binary/type/TypeRegistry.d.ts.map +1 -1
- package/src/core/binary/type/TypeRegistry.js +38 -42
- package/src/core/bvh2/visual/BVHGeometry.d.ts.map +1 -1
- package/src/core/bvh2/visual/BVHGeometry.js +0 -3
- package/src/core/codegen/LineBuilder.d.ts.map +1 -1
- package/src/core/codegen/LineBuilder.js +0 -5
- package/src/core/collection/array/array_copy.spec.d.ts +2 -0
- package/src/core/collection/array/array_copy.spec.d.ts.map +1 -0
- package/src/core/collection/array/array_copy.spec.js +19 -0
- package/src/core/collection/list/List.d.ts.map +1 -1
- package/src/core/collection/list/List.js +55 -30
- package/src/core/collection/list/List.spec.js +101 -0
- package/src/core/collection/list/ListForwarder.d.ts.map +1 -1
- package/src/core/collection/list/ListForwarder.js +49 -53
- package/src/core/collection/list/ListForwarder.spec.js +2 -0
- package/src/core/collection/list/SortedListProjection.d.ts +4 -1
- package/src/core/collection/list/SortedListProjection.d.ts.map +1 -1
- package/src/core/collection/list/SortedListProjection.js +4 -1
- package/src/core/collection/map/AbstractAsyncMap.d.ts.map +1 -1
- package/src/core/collection/map/AbstractAsyncMap.js +0 -3
- package/src/core/collection/map/AsyncMapWrapper.d.ts +6 -10
- package/src/core/collection/map/AsyncMapWrapper.d.ts.map +1 -1
- package/src/core/collection/map/AsyncMapWrapper.js +14 -9
- package/src/core/collection/map/HashMap.d.ts.map +1 -1
- package/src/core/collection/map/HashMap.js +14 -0
- package/src/core/collection/map/ObservedMap.d.ts +12 -3
- package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
- package/src/core/collection/map/ObservedMap.js +14 -4
- package/src/core/collection/queue/Deque.d.ts.map +1 -1
- package/src/core/collection/queue/Deque.js +100 -95
- package/src/core/collection/set/ArraySet.d.ts.map +1 -0
- package/src/core/collection/set/{Set.js → ArraySet.js} +3 -7
- package/src/core/collection/set/set_remove.d.ts +3 -3
- package/src/core/collection/set/set_remove.d.ts.map +1 -1
- package/src/core/collection/set/set_remove.js +5 -5
- package/src/core/collection/table/RowFirstTable.d.ts.map +1 -1
- package/src/core/collection/table/RowFirstTable.js +0 -5
- package/src/core/color/oklab/find_gamut_intersection.js +1 -1
- package/src/core/color/parse_color.d.ts.map +1 -1
- package/src/core/color/parse_color.js +1 -5
- package/src/core/geom/2d/Rectangle.d.ts +54 -5
- package/src/core/geom/2d/Rectangle.d.ts.map +1 -1
- package/src/core/geom/2d/Rectangle.js +70 -7
- package/src/core/geom/2d/aabb/AABB2.d.ts.map +1 -1
- package/src/core/geom/2d/aabb/AABB2.js +0 -6
- package/src/core/geom/2d/circle/Circle.d.ts +1 -1
- package/src/core/geom/2d/circle/Circle.js +1 -1
- package/src/core/geom/2d/compute_triangle_area_2d.d.ts.map +1 -1
- package/src/core/geom/2d/compute_triangle_area_2d.js +7 -1
- package/src/core/geom/2d/shape/AbstractShape.d.ts +2 -0
- package/src/core/geom/2d/shape/AbstractShape.d.ts.map +1 -1
- package/src/core/geom/2d/shape/AbstractShape.js +8 -2
- package/src/core/geom/2d/shape/CircleShape.d.ts +14 -0
- package/src/core/geom/2d/shape/CircleShape.d.ts.map +1 -1
- package/src/core/geom/2d/shape/CircleShape.js +64 -22
- package/src/core/geom/2d/uv_map_circle_to_square.d.ts +8 -0
- package/src/core/geom/2d/uv_map_circle_to_square.d.ts.map +1 -0
- package/src/core/geom/2d/{UvUtils.js → uv_map_circle_to_square.js} +2 -17
- package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts +2 -0
- package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts.map +1 -0
- package/src/core/geom/2d/uv_map_circle_to_square.spec.js +28 -0
- package/src/core/geom/2d/uv_map_square_to_circle.d.ts +8 -0
- package/src/core/geom/2d/uv_map_square_to_circle.d.ts.map +1 -0
- package/src/core/geom/2d/uv_map_square_to_circle.js +14 -0
- package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts +2 -0
- package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts.map +1 -0
- package/src/core/geom/2d/uv_map_square_to_circle.spec.js +30 -0
- package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
- package/src/core/geom/3d/aabb/AABB3.js +0 -5
- package/src/core/geom/3d/morton/Morton.d.ts.map +1 -1
- package/src/core/geom/3d/morton/Morton.js +0 -3
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +11 -11
- package/src/core/geom/Quaternion.d.ts.map +1 -1
- package/src/core/geom/Quaternion.js +0 -5
- package/src/core/geom/Vector3.d.ts +13 -4
- package/src/core/geom/Vector3.d.ts.map +1 -1
- package/src/core/geom/Vector3.js +83 -36
- package/src/core/geom/Vector3.spec.js +113 -12
- package/src/core/geom/Vector4.d.ts.map +1 -1
- package/src/core/geom/Vector4.js +0 -4
- package/src/core/graph/Edge.d.ts.map +1 -1
- package/src/core/graph/Edge.js +0 -5
- package/src/core/graph/WeightedEdge.d.ts.map +1 -1
- package/src/core/json/JsonUtils.d.ts.map +1 -1
- package/src/core/json/JsonUtils.js +0 -4
- package/src/core/math/random/MersenneTwister.d.ts +1 -2
- package/src/core/math/random/MersenneTwister.d.ts.map +1 -1
- package/src/core/math/random/MersenneTwister.js +134 -133
- package/src/core/model/BooleanVector3.d.ts.map +1 -1
- package/src/core/model/BooleanVector3.js +108 -108
- package/src/core/model/BoundedValue.d.ts +116 -0
- package/src/core/model/BoundedValue.d.ts.map +1 -0
- package/src/core/model/BoundedValue.js +214 -217
- package/src/core/model/LinearValue.d.ts +84 -0
- package/src/core/model/LinearValue.d.ts.map +1 -0
- package/src/core/model/LinearValue.js +116 -117
- package/src/core/model/ObservedEnum.d.ts.map +1 -1
- package/src/core/model/ObservedEnum.js +82 -80
- package/src/core/model/ObservedValue.d.ts +10 -17
- package/src/core/model/ObservedValue.d.ts.map +1 -1
- package/src/core/model/ObservedValue.js +85 -88
- package/src/core/model/object/ObjectPoolFactory.d.ts +1 -9
- package/src/core/model/object/ObjectPoolFactory.d.ts.map +1 -1
- package/src/core/model/object/ObjectPoolFactory.js +73 -73
- package/src/core/model/scheme/Schema.d.ts +0 -6
- package/src/core/model/scheme/Schema.d.ts.map +1 -1
- package/src/core/model/scheme/Schema.js +50 -48
- package/src/core/model/scheme/SchemeRegistry.d.ts +6 -1
- package/src/core/model/scheme/SchemeRegistry.d.ts.map +1 -1
- package/src/core/model/scheme/SchemeRegistry.js +46 -44
- package/src/core/process/Future.d.ts +14 -9
- package/src/core/process/Future.d.ts.map +1 -1
- package/src/core/process/Future.js +96 -98
- package/src/core/process/executor/ConcurrentExecutor.d.ts.map +1 -1
- package/src/core/process/executor/ConcurrentExecutor.js +0 -3
- package/src/core/process/task/Task.d.ts.map +1 -1
- package/src/core/process/task/Task.js +0 -5
- package/src/core/process/task/TaskGroup.d.ts.map +1 -1
- package/src/core/process/task/TaskGroup.js +178 -180
- package/src/core/process/task/TaskSignal.d.ts.map +1 -1
- package/src/core/process/task/TaskSignal.js +0 -5
- package/src/core/process/task/TaskState.d.ts.map +1 -1
- package/src/core/process/task/TaskState.js +0 -4
- package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
- package/src/core/process/worker/WorkerBuilder.js +0 -5
- package/src/core/process/worker/WorkerProxy.d.ts.map +1 -1
- package/src/core/process/worker/WorkerProxy.js +0 -5
- package/src/engine/Clock.d.ts.map +1 -1
- package/src/engine/Clock.js +0 -5
- package/src/engine/Engine.js +4 -4
- package/src/engine/EntityCreator.d.ts.map +1 -1
- package/src/engine/EntityCreator.js +7 -10
- package/src/engine/animation/AnimatedActions.d.ts.map +1 -1
- package/src/engine/animation/AnimatedActions.js +0 -5
- package/src/engine/animation/Animations.d.ts.map +1 -1
- package/src/engine/animation/Animations.js +1 -6
- package/src/engine/animation/EntityAnimation.js +1 -4
- package/src/engine/animation/Tween.js +1 -4
- package/src/engine/animation/keyed2/AnimationTrack.d.ts +0 -6
- package/src/engine/animation/keyed2/AnimationTrack.d.ts.map +1 -1
- package/src/engine/animation/keyed2/AnimationTrack.js +154 -152
- package/src/engine/animation/keyed2/AnimationTrackPlayback.d.ts +0 -10
- package/src/engine/animation/keyed2/AnimationTrackPlayback.d.ts.map +1 -1
- package/src/engine/animation/keyed2/AnimationTrackPlayback.js +173 -171
- package/src/engine/asset/AssetManager.d.ts.map +1 -1
- package/src/engine/asset/AssetManager.js +0 -5
- package/src/engine/asset/preloader/AssetLevel.js +0 -3
- package/src/engine/ecs/EntityManager.d.ts.map +1 -1
- package/src/engine/ecs/EntityManager.js +0 -4
- package/src/engine/ecs/System.d.ts.map +1 -1
- package/src/engine/ecs/System.js +0 -5
- package/src/engine/ecs/animation/Animation.d.ts.map +1 -1
- package/src/engine/ecs/animation/Animation.js +1 -19
- package/src/engine/ecs/components/Motion.d.ts.map +1 -1
- package/src/engine/ecs/components/Motion.js +0 -5
- package/src/engine/ecs/components/PropertySet.d.ts +8 -1
- package/src/engine/ecs/components/PropertySet.d.ts.map +1 -1
- package/src/engine/ecs/components/PropertySet.js +87 -83
- package/src/engine/ecs/components/Script.d.ts +0 -16
- package/src/engine/ecs/components/Script.d.ts.map +1 -1
- package/src/engine/ecs/components/Script.js +14 -18
- package/src/engine/ecs/components/Tag.d.ts.map +1 -1
- package/src/engine/ecs/components/Tag.js +4 -5
- package/src/engine/ecs/components/Timer.d.ts +0 -5
- package/src/engine/ecs/components/Timer.d.ts.map +1 -1
- package/src/engine/ecs/components/Timer.js +0 -5
- package/src/engine/ecs/grid/HeightMap2NormalMap.d.ts.map +1 -1
- package/src/engine/ecs/grid/HeightMap2NormalMap.js +2 -6
- package/src/engine/ecs/grid/HeightSampler2NormalSamplerSoft.d.ts.map +1 -1
- package/src/engine/ecs/grid/HeightSampler2NormalSamplerSoft.js +0 -3
- package/src/engine/ecs/grid/NormalMap2AOMap.d.ts.map +1 -1
- package/src/engine/ecs/grid/NormalMap2AOMap.js +3 -8
- package/src/engine/ecs/gui/GUIElement.d.ts.map +1 -1
- package/src/engine/ecs/gui/GUIElement.js +0 -3
- package/src/engine/ecs/gui/GUIElementSystem.d.ts.map +1 -1
- package/src/engine/ecs/gui/GUIElementSystem.js +0 -4
- package/src/engine/ecs/gui/hud/HeadsUpDisplay.d.ts.map +1 -1
- package/src/engine/ecs/gui/hud/HeadsUpDisplay.js +0 -7
- package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.d.ts.map +1 -1
- package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +0 -5
- package/src/engine/ecs/gui/menu/radial/RadialContextMenu.d.ts.map +1 -1
- package/src/engine/ecs/gui/menu/radial/RadialContextMenu.js +5 -8
- package/src/engine/ecs/gui/position/ViewportPosition.d.ts.map +1 -1
- package/src/engine/ecs/gui/position/ViewportPosition.js +0 -4
- package/src/engine/ecs/gui/position/ViewportPositionSystem.d.ts +1 -2
- package/src/engine/ecs/gui/position/ViewportPositionSystem.d.ts.map +1 -1
- package/src/engine/ecs/gui/position/ViewportPositionSystem.js +6 -10
- package/src/engine/ecs/ik/IKProblem.d.ts +1 -2
- package/src/engine/ecs/ik/IKProblem.d.ts.map +1 -1
- package/src/engine/ecs/renderable/RenderSystem.d.ts.map +1 -1
- package/src/engine/ecs/renderable/RenderSystem.js +0 -3
- package/src/engine/ecs/renderable/Renderable.d.ts.map +1 -1
- package/src/engine/ecs/renderable/Renderable.js +0 -5
- package/src/engine/ecs/systems/AnimationSystem.d.ts.map +1 -1
- package/src/engine/ecs/systems/AnimationSystem.js +9 -17
- package/src/engine/ecs/systems/MotionSystem.d.ts.map +1 -1
- package/src/engine/ecs/systems/MotionSystem.js +1 -6
- package/src/engine/ecs/systems/ScriptSystem.d.ts.map +1 -1
- package/src/engine/ecs/systems/ScriptSystem.js +1 -6
- package/src/engine/ecs/systems/TimerSystem.d.ts.map +1 -1
- package/src/engine/ecs/systems/TimerSystem.js +1 -6
- package/src/engine/ecs/team/Team.d.ts.map +1 -1
- package/src/engine/ecs/team/Team.js +0 -3
- package/src/engine/ecs/terrain/BufferedGeometryArraysBuilder.d.ts.map +1 -1
- package/src/engine/ecs/terrain/BufferedGeometryArraysBuilder.js +0 -5
- package/src/engine/ecs/terrain/TerrainClouds.d.ts.map +1 -1
- package/src/engine/ecs/terrain/TerrainClouds.js +0 -5
- package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/Terrain.js +0 -5
- package/src/engine/ecs/terrain/ecs/cling/ClingToTerrain.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/cling/ClingToTerrain.js +0 -3
- package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSystem.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSystem.js +11 -14
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.d.ts.map +1 -1
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +0 -5
- package/src/engine/ecs/terrain/tiles/TerrainTile.d.ts.map +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +0 -5
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts.map +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +0 -3
- package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +0 -4
- package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
- package/src/engine/ecs/transform/Transform.js +0 -4
- package/src/engine/google/gapi.js +0 -4
- package/src/engine/graphics/FrameThrottle.d.ts +0 -4
- package/src/engine/graphics/FrameThrottle.d.ts.map +1 -1
- package/src/engine/graphics/FrameThrottle.js +0 -5
- package/src/engine/graphics/GraphicsEngine.d.ts.map +1 -1
- package/src/engine/graphics/GraphicsEngine.js +1 -6
- package/src/engine/graphics/composit/LayerCompositer.d.ts.map +1 -1
- package/src/engine/graphics/composit/LayerCompositer.js +2 -5
- package/src/engine/graphics/ecs/animation/AnimationController.d.ts.map +1 -1
- package/src/engine/graphics/ecs/animation/AnimationController.js +0 -5
- package/src/engine/graphics/ecs/animation/AnimationControllerSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/animation/AnimationControllerSystem.js +2 -7
- package/src/engine/graphics/ecs/animation/AnimationRule.d.ts +0 -1
- package/src/engine/graphics/ecs/animation/AnimationRule.d.ts.map +1 -1
- package/src/engine/graphics/ecs/animation/AnimationRule.js +70 -66
- package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +0 -5
- package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/CameraSystem.js +0 -5
- package/src/engine/graphics/ecs/camera/FrustumProjector.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/FrustumProjector.js +0 -5
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -9
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +3 -8
- package/src/engine/graphics/ecs/highlight/Highlight.d.ts.map +1 -1
- package/src/engine/graphics/ecs/highlight/Highlight.js +0 -3
- package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.js +3 -8
- package/src/engine/graphics/ecs/light/Light.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/Light.js +2 -6
- package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/LightSystem.js +0 -5
- package/src/engine/graphics/ecs/mesh/Mesh.d.ts.map +1 -1
- package/src/engine/graphics/ecs/mesh/Mesh.js +0 -3
- package/src/engine/graphics/ecs/mesh/MeshSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +0 -5
- package/src/engine/graphics/ecs/trail2d/Trail2D.d.ts.map +1 -1
- package/src/engine/graphics/ecs/trail2d/Trail2D.js +0 -5
- package/src/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +0 -5
- package/src/engine/graphics/ecs/water/Water.d.ts.map +1 -1
- package/src/engine/graphics/ecs/water/Water.js +0 -5
- package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/water/WaterSystem.js +0 -3
- package/src/engine/graphics/filter/ImageFilter.d.ts.map +1 -1
- package/src/engine/graphics/filter/ImageFilter.js +0 -5
- package/src/engine/graphics/geometry/BufferGeometryWrap.js +1 -3
- package/src/engine/graphics/geometry/buffered/ComputeNormals.d.ts.map +1 -1
- package/src/engine/graphics/geometry/buffered/ComputeNormals.js +0 -5
- package/src/engine/graphics/geometry/ribbon/Ribbon.d.ts.map +1 -1
- package/src/engine/graphics/geometry/ribbon/Ribbon.js +1 -4
- package/src/engine/graphics/material/SplatMaterial.d.ts.map +1 -1
- package/src/engine/graphics/material/SplatMaterial.js +0 -3
- package/src/engine/graphics/material/WaterMaterial.d.ts.map +1 -1
- package/src/engine/graphics/material/WaterMaterial.js +0 -3
- package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.d.ts +0 -5
- package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.js +114 -114
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.d.ts +0 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +347 -348
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.d.ts +1 -3
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterSet.d.ts +0 -1
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterSet.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterSet.js +110 -111
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterSheet.d.ts +0 -9
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterSheet.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterSheet.js +70 -66
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterTrackSet.d.ts +0 -5
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterTrackSet.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterTrackSet.js +82 -82
- package/src/engine/graphics/particles/particular/group/Operation.d.ts +0 -7
- package/src/engine/graphics/particles/particular/group/Operation.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/group/Operation.js +16 -14
- package/src/engine/graphics/particles/particular/group/ParticleAttribute.d.ts +0 -9
- package/src/engine/graphics/particles/particular/group/ParticleAttribute.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/group/ParticleAttribute.js +23 -21
- package/src/engine/graphics/particles/particular/group/ParticleGroup.d.ts +2 -10
- package/src/engine/graphics/particles/particular/group/ParticleGroup.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/group/ParticleGroup.js +463 -464
- package/src/engine/graphics/particles/particular/group/ParticleSpecification.d.ts +0 -2
- package/src/engine/graphics/particles/particular/group/ParticleSpecification.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/group/ParticleSpecification.js +39 -33
- package/src/engine/graphics/render/buffer/FrameBufferManager.d.ts +6 -1
- package/src/engine/graphics/render/buffer/FrameBufferManager.d.ts.map +1 -1
- package/src/engine/graphics/render/buffer/FrameBufferManager.js +166 -163
- package/src/engine/graphics/render/layers/RenderLayer.d.ts.map +1 -1
- package/src/engine/graphics/render/layers/RenderLayer.js +0 -5
- package/src/engine/graphics/shaders/AlphaBlendShader.js +1 -3
- package/src/engine/graphics/shaders/AmbientOcclusionShader.d.ts.map +1 -1
- package/src/engine/graphics/shaders/AmbientOcclusionShader.js +0 -3
- package/src/engine/graphics/shaders/ClearShader.js +1 -3
- package/src/engine/graphics/shaders/CopyShader.d.ts +0 -3
- package/src/engine/graphics/shaders/CopyShader.d.ts.map +1 -1
- package/src/engine/graphics/shaders/CopyShader.js +1 -3
- package/src/engine/graphics/shaders/NormalMapShader2.d.ts.map +1 -1
- package/src/engine/graphics/shaders/NormalMapShader2.js +0 -5
- package/src/engine/graphics/shaders/TerrainShader.js +0 -4
- package/src/engine/graphics/shaders/WaterShader.js +0 -3
- package/src/engine/graphics/shaders/lib/ShaderChunks.js +1 -3
- package/src/engine/graphics/texture/Canvas2Sampler2D.d.ts.map +1 -1
- package/src/engine/graphics/texture/Canvas2Sampler2D.js +1 -4
- package/src/engine/graphics/texture/CheckersTexture.d.ts.map +1 -1
- package/src/engine/graphics/texture/CheckersTexture.js +0 -3
- package/src/engine/graphics/texture/CheckersTextureURI.js +1 -3
- package/src/engine/graphics/texture/sampler/Sampler2D.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/Sampler2D.js +0 -5
- package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.js +0 -5
- package/src/engine/graphics/texture/sampler/Sampler2D2Texture.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/Sampler2D2Texture.js +0 -3
- package/src/engine/graphics/three/ThreeFactory.d.ts.map +1 -1
- package/src/engine/graphics/three/ThreeFactory.js +0 -5
- package/src/engine/grid/grid2transform/GridPosition2Transform.d.ts.map +1 -1
- package/src/engine/grid/grid2transform/GridPosition2Transform.js +0 -4
- package/src/engine/grid/grid2transform/GridPosition2TransformSystem.d.ts.map +1 -1
- package/src/engine/grid/grid2transform/GridPosition2TransformSystem.js +4 -7
- package/src/engine/grid/obstacle/GridObstacle.d.ts.map +1 -1
- package/src/engine/grid/obstacle/GridObstacle.js +0 -5
- package/src/engine/grid/position/GridPosition.d.ts.map +1 -1
- package/src/engine/grid/position/GridPosition.js +0 -4
- package/src/engine/grid/position/GridPositionSystem.d.ts.map +1 -1
- package/src/engine/grid/position/GridPositionSystem.js +1 -4
- package/src/engine/input/devices/KeyCodes.d.ts.map +1 -1
- package/src/engine/input/devices/KeyCodes.js +3 -4
- package/src/engine/input/devices/KeyboardDevice.d.ts.map +1 -1
- package/src/engine/input/devices/KeyboardDevice.js +0 -4
- package/src/engine/input/devices/PointerDevice.d.ts.map +1 -1
- package/src/engine/input/devices/PointerDevice.js +0 -3
- package/src/engine/input/ecs/components/InputController.d.ts.map +1 -1
- package/src/engine/input/ecs/components/InputController.js +1 -5
- package/src/engine/input/ecs/controllers/KeyboardCameraController.d.ts.map +1 -1
- package/src/engine/input/ecs/controllers/KeyboardCameraController.js +5 -10
- package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
- package/src/engine/input/ecs/systems/InputControllerSystem.js +78 -78
- package/src/engine/input/ecs/util/TopDownCameraControllerHelper.d.ts.map +1 -1
- package/src/engine/input/ecs/util/TopDownCameraControllerHelper.js +3 -6
- package/src/engine/intelligence/mcts/MonteCarlo.spec.js +78 -76
- package/src/engine/navigation/ecs/components/Path.d.ts.map +1 -1
- package/src/engine/navigation/ecs/components/Path.js +0 -5
- package/src/engine/navigation/ecs/path_following/PathFollower.d.ts.map +1 -1
- package/src/engine/navigation/ecs/path_following/PathFollower.js +1 -6
- package/src/engine/navigation/ecs/path_following/PathFollowingSystem.d.ts.map +1 -1
- package/src/engine/navigation/ecs/path_following/PathFollowingSystem.js +5 -12
- package/src/engine/network/DataChannel.js +284 -284
- package/src/engine/network/xhr.d.ts +0 -3
- package/src/engine/network/xhr.d.ts.map +1 -1
- package/src/engine/network/xhr.js +0 -3
- package/src/engine/notify/Notification.d.ts +1 -1
- package/src/engine/notify/Notification.d.ts.map +1 -1
- package/src/engine/notify/Notification.js +1 -6
- package/src/engine/notify/NotificationLog.d.ts.map +1 -1
- package/src/engine/notify/NotificationLog.js +0 -5
- package/src/engine/options/OptionsView.d.ts.map +1 -1
- package/src/engine/options/OptionsView.js +1 -6
- package/src/engine/physics/ammo/Body.js +0 -3
- package/src/engine/physics/ammo/PhysicsWorker.d.ts.map +1 -1
- package/src/engine/physics/ammo/PhysicsWorker.js +1 -3
- package/src/engine/physics/ammo/World.d.ts +68 -0
- package/src/engine/physics/ammo/World.d.ts.map +1 -0
- package/src/engine/physics/ammo/World.js +277 -278
- package/src/engine/physics/ammo/shapes/BoxShape.js +0 -3
- package/src/engine/physics/ammo/shapes/CapsuleShape.js +0 -3
- package/src/engine/physics/ammo/shapes/MeshShape.js +0 -3
- package/src/engine/physics/ammo/shapes/PlaneShape.js +0 -3
- package/src/engine/physics/ammo/shapes/Shape.js +1 -3
- package/src/engine/physics/ammo/shapes/SphereShape.js +0 -3
- package/src/engine/physics/cannon/CannonJSPhysicsSystem.d.ts.map +1 -1
- package/src/engine/physics/cannon/CannonJSPhysicsSystem.js +3 -6
- package/src/engine/save/GameStateLoader.d.ts.map +1 -1
- package/src/engine/save/GameStateLoader.js +1 -5
- package/src/engine/save/Storage.d.ts.map +1 -1
- package/src/engine/save/Storage.js +0 -7
- package/src/engine/scene/Scene.d.ts.map +1 -1
- package/src/engine/scene/Scene.js +2 -7
- package/src/engine/scene/SceneManager.d.ts.map +1 -1
- package/src/engine/scene/SceneManager.js +1 -4
- package/src/engine/simulation/DormandPrince.d.ts +0 -1
- package/src/engine/simulation/DormandPrince.d.ts.map +1 -1
- package/src/engine/simulation/DormandPrince.js +5 -5
- package/src/engine/simulation/Ticker.d.ts.map +1 -1
- package/src/engine/simulation/Ticker.js +0 -3
- package/src/engine/sound/ecs/SoundController.d.ts +0 -7
- package/src/engine/sound/ecs/SoundController.d.ts.map +1 -1
- package/src/engine/sound/ecs/SoundController.js +118 -119
- package/src/engine/sound/ecs/SoundControllerSystem.d.ts.map +1 -1
- package/src/engine/sound/ecs/SoundControllerSystem.js +3 -8
- package/src/engine/sound/ecs/SoundListener.d.ts +0 -1
- package/src/engine/sound/ecs/SoundListener.d.ts.map +1 -1
- package/src/engine/sound/ecs/SoundListener.js +26 -29
- package/src/engine/sound/ecs/SoundListenerSystem.d.ts.map +1 -1
- package/src/engine/sound/ecs/SoundListenerSystem.js +0 -5
- package/src/engine/sound/ecs/emitter/SoundEmitter.d.ts.map +1 -1
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +0 -5
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts.map +1 -1
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +0 -7
- package/src/engine/ui/GUIEngine.d.ts.map +1 -1
- package/src/engine/ui/GUIEngine.js +0 -5
- package/src/engine/ui/tiles2d/TileGrid.d.ts.map +1 -1
- package/src/engine/ui/tiles2d/TileGrid.js +1 -4
- package/src/generation/markers/debug/visualizeMarkers.js +10 -10
- package/src/view/DOM.js +1 -3
- package/src/view/SVG.d.ts +0 -3
- package/src/view/SVG.d.ts.map +1 -1
- package/src/view/SVG.js +0 -4
- package/src/view/asset/PreloaderView.d.ts.map +1 -1
- package/src/view/asset/PreloaderView.js +0 -3
- package/src/view/common/LabelView.d.ts +1 -6
- package/src/view/common/LabelView.d.ts.map +1 -1
- package/src/view/common/LabelView.js +24 -33
- package/src/view/common/ListView.d.ts.map +1 -1
- package/src/view/common/ListView.js +0 -6
- package/src/view/common/MeshView.js +3 -6
- package/src/view/common/VirtualListView.d.ts.map +1 -1
- package/src/view/common/VirtualListView.js +0 -5
- package/src/view/common/dnd/DragAndDropContext.d.ts +1 -2
- package/src/view/common/dnd/DragAndDropContext.d.ts.map +1 -1
- package/src/view/common/dnd/DragAndDropContext.js +107 -110
- package/src/view/controller/GuiController.d.ts.map +1 -1
- package/src/view/controller/GuiController.js +1 -6
- package/src/view/controller/controls/BooleanVector3Control.d.ts +1 -1
- package/src/view/controller/controls/BooleanVector3Control.d.ts.map +1 -1
- package/src/view/controller/controls/GuiControl.js +2 -7
- package/src/view/controller/controls/Vector1Control.d.ts +1 -1
- package/src/view/controller/controls/Vector1Control.d.ts.map +1 -1
- package/src/view/controller/controls/Vector1Control.js +2 -7
- package/src/view/controller/controls/Vector2Control.d.ts.map +1 -1
- package/src/view/controller/controls/Vector2Control.js +0 -4
- package/src/view/controller/controls/Vector3Control.d.ts.map +1 -1
- package/src/view/controller/controls/Vector3Control.js +0 -3
- package/src/view/elements/ConfirmationDialogView.d.ts.map +1 -1
- package/src/view/elements/ConfirmationDialogView.js +1 -6
- package/src/view/elements/DropDownSelectionView.d.ts.map +1 -1
- package/src/view/elements/DropDownSelectionView.js +0 -5
- package/src/view/elements/EmptyView.d.ts.map +1 -1
- package/src/view/elements/EmptyView.js +0 -4
- package/src/view/elements/Group.d.ts.map +1 -1
- package/src/view/elements/Group.js +0 -3
- package/src/view/elements/MeshPreview.d.ts.map +1 -1
- package/src/view/elements/MeshPreview.js +5 -8
- package/src/view/elements/SimpleWindow.d.ts +1 -1
- package/src/view/elements/SimpleWindow.d.ts.map +1 -1
- package/src/view/elements/SimpleWindow.js +5 -11
- package/src/view/elements/button/ButtonView.d.ts.map +1 -1
- package/src/view/elements/button/ButtonView.js +1 -5
- package/src/view/elements/image/ImageView.d.ts.map +1 -1
- package/src/view/elements/image/ImageView.js +0 -4
- package/src/view/elements/image/SvgImageView.d.ts.map +1 -1
- package/src/view/elements/image/SvgImageView.js +2 -7
- package/src/view/elements/label/LabeledValueView.d.ts.map +1 -1
- package/src/view/elements/label/LabeledValueView.js +3 -8
- package/src/view/elements/navigation/ViewStack.d.ts +0 -7
- package/src/view/elements/navigation/ViewStack.d.ts.map +1 -1
- package/src/view/elements/navigation/ViewStack.js +17 -19
- package/src/view/elements/notify/NotificationView.js +1 -4
- package/src/view/elements/notify/ToastLogView.d.ts.map +1 -1
- package/src/view/elements/notify/ToastLogView.js +0 -3
- package/src/view/elements/progress/SmoothProgressBar.d.ts +72 -0
- package/src/view/elements/progress/SmoothProgressBar.d.ts.map +1 -0
- package/src/view/elements/radial/RadialMenu.d.ts.map +1 -1
- package/src/view/elements/radial/RadialMenu.js +1 -6
- package/src/view/elements/radial/RadialMenuElement.d.ts.map +1 -1
- package/src/view/elements/radial/RadialMenuElement.js +1 -4
- package/src/view/elements/radial/RadialProgressView.d.ts +1 -1
- package/src/view/elements/radial/RadialProgressView.d.ts.map +1 -1
- package/src/view/elements/radial/RadialProgressView.js +4 -9
- package/src/view/elements/tiles2d/Tile.d.ts.map +1 -1
- package/src/view/elements/tiles2d/Tile.js +3 -6
- package/src/view/elements/tiles2d/TileGrid.d.ts.map +1 -1
- package/src/view/elements/tiles2d/TileGrid.js +0 -5
- package/src/view/minimap/Minimap.d.ts.map +1 -1
- package/src/view/minimap/Minimap.js +11 -16
- package/src/view/minimap/dom/MinimapCameraView.d.ts +1 -2
- package/src/view/minimap/dom/MinimapCameraView.d.ts.map +1 -1
- package/src/view/minimap/dom/MinimapTerrainView.d.ts +1 -1
- package/src/view/minimap/dom/MinimapTerrainView.d.ts.map +1 -1
- package/src/view/minimap/gl/MarkerGL.d.ts +2 -12
- package/src/view/minimap/gl/MarkerGL.d.ts.map +1 -1
- package/src/view/minimap/gl/MarkerGL.js +60 -56
- package/src/view/minimap/gl/MinimapMarkersGL.d.ts +1 -1
- package/src/view/minimap/gl/MinimapMarkersGL.d.ts.map +1 -1
- package/src/view/minimap/gl/MinimapTerrainGL.d.ts +1 -2
- package/src/view/minimap/gl/MinimapTerrainGL.d.ts.map +1 -1
- package/src/view/renderModel.d.ts.map +1 -1
- package/src/view/renderModel.js +3 -7
- package/src/view/task/TaskProgressView.d.ts.map +1 -1
- package/src/view/task/TaskProgressView.js +0 -5
- package/src/core/collection/set/Set.d.ts.map +0 -1
- package/src/core/geom/2d/Geometry2D.d.ts +0 -31
- package/src/core/geom/2d/Geometry2D.d.ts.map +0 -1
- package/src/core/geom/2d/Geometry2D.js +0 -59
- package/src/core/geom/2d/UvUtils.d.ts +0 -15
- package/src/core/geom/2d/UvUtils.d.ts.map +0 -1
- package/src/core/geom/2d/UvUtils.spec.d.ts +0 -2
- package/src/core/geom/2d/UvUtils.spec.d.ts.map +0 -1
- package/src/core/geom/2d/UvUtils.spec.js +0 -55
- package/src/engine/asset/loaders/LegacyThreeJSONAssetLoader.d.ts +0 -9
- package/src/engine/asset/loaders/LegacyThreeJSONAssetLoader.d.ts.map +0 -1
- package/src/engine/asset/loaders/LegacyThreeJSONAssetLoader.js +0 -105
- package/src/engine/graphics/geometry/decimation/SimplifyModifier.d.ts +0 -117
- package/src/engine/graphics/geometry/decimation/SimplifyModifier.d.ts.map +0 -1
- package/src/engine/graphics/geometry/decimation/SimplifyModifier.js +0 -971
- package/src/engine/graphics/loader/threejs/GLTFLoader.js +0 -3179
- package/src/engine/graphics/loader/threejs/LegacyJSONLoader.d.ts +0 -6
- package/src/engine/graphics/loader/threejs/LegacyJSONLoader.d.ts.map +0 -1
- package/src/engine/graphics/loader/threejs/LegacyJSONLoader.js +0 -845
- package/src/engine/graphics/postprocess/Postprocess.js +0 -284
- package/src/engine/graphics/postprocess/threejs/Mirror.js +0 -330
- package/src/engine/graphics/postprocess/threejs/WaterShader.js +0 -306
- package/src/engine/graphics/postprocess/threejs/postprocessing/AdaptiveToneMappingPass.js +0 -338
- package/src/engine/graphics/postprocess/threejs/postprocessing/BloomPass.js +0 -132
- package/src/engine/graphics/postprocess/threejs/postprocessing/BokehPass.js +0 -115
- package/src/engine/graphics/postprocess/threejs/postprocessing/ClearMaskPass.d.ts +0 -4
- package/src/engine/graphics/postprocess/threejs/postprocessing/ClearMaskPass.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/ClearMaskPass.js +0 -23
- package/src/engine/graphics/postprocess/threejs/postprocessing/DotScreenPass.d.ts +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/DotScreenPass.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/DotScreenPass.js +0 -60
- package/src/engine/graphics/postprocess/threejs/postprocessing/EffectComposer.js +0 -150
- package/src/engine/graphics/postprocess/threejs/postprocessing/FilmPass.d.ts +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/FilmPass.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/FilmPass.js +0 -61
- package/src/engine/graphics/postprocess/threejs/postprocessing/GlitchPass.d.ts +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/GlitchPass.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/GlitchPass.js +0 -117
- package/src/engine/graphics/postprocess/threejs/postprocessing/RenderPass.js +0 -63
- package/src/engine/graphics/postprocess/threejs/postprocessing/SMAAPass.js +0 -187
- package/src/engine/graphics/postprocess/threejs/postprocessing/SavePass.d.ts +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/SavePass.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/SavePass.js +0 -67
- package/src/engine/graphics/postprocess/threejs/postprocessing/TexturePass.js +0 -50
- package/src/engine/graphics/postprocess/threejs/shaders/BokehShader.d.ts +0 -42
- package/src/engine/graphics/postprocess/threejs/shaders/BokehShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/BokehShader.js +0 -117
- package/src/engine/graphics/postprocess/threejs/shaders/ConvolutionShader.d.ts +0 -30
- package/src/engine/graphics/postprocess/threejs/shaders/ConvolutionShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/ConvolutionShader.js +0 -106
- package/src/engine/graphics/postprocess/threejs/shaders/FXAAShader.d.ts +0 -19
- package/src/engine/graphics/postprocess/threejs/shaders/FXAAShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/FXAAShader.js +0 -90
- package/src/engine/graphics/postprocess/threejs/shaders/GammaCorrectionShader.d.ts +0 -12
- package/src/engine/graphics/postprocess/threejs/shaders/GammaCorrectionShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/GammaCorrectionShader.js +0 -52
- package/src/engine/graphics/postprocess/threejs/shaders/LuminosityShader.d.ts +0 -12
- package/src/engine/graphics/postprocess/threejs/shaders/LuminosityShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/LuminosityShader.js +0 -51
- package/src/engine/graphics/postprocess/threejs/shaders/SMAAShader.d.ts +0 -76
- package/src/engine/graphics/postprocess/threejs/shaders/SMAAShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/SMAAShader.js +0 -468
- package/src/engine/graphics/postprocess/threejs/shaders/SSAOShader.d.ts +0 -61
- package/src/engine/graphics/postprocess/threejs/shaders/SSAOShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/SSAOShader.js +0 -230
- package/src/engine/graphics/postprocess/threejs/shaders/ToneMapShader.d.ts +0 -36
- package/src/engine/graphics/postprocess/threejs/shaders/ToneMapShader.d.ts.map +0 -1
- package/src/engine/graphics/postprocess/threejs/shaders/ToneMapShader.js +0 -76
- package/src/engine/graphics/shaders/GaussianBlurShader.d.ts +0 -22
- package/src/engine/graphics/shaders/GaussianBlurShader.d.ts.map +0 -1
- package/src/engine/graphics/shaders/GaussianBlurShader.js +0 -79
- package/src/engine/graphics/shaders/GaussianGlowShader.d.ts +0 -26
- package/src/engine/graphics/shaders/GaussianGlowShader.d.ts.map +0 -1
- package/src/engine/graphics/shaders/GaussianGlowShader.js +0 -83
- package/src/engine/graphics/shaders/NormalMapShader.d.ts +0 -33
- package/src/engine/graphics/shaders/NormalMapShader.d.ts.map +0 -1
- package/src/engine/graphics/shaders/NormalMapShader.js +0 -62
- package/src/engine/graphics/shaders/SoftOutlineShader.d.ts +0 -3
- package/src/engine/graphics/shaders/SoftOutlineShader.d.ts.map +0 -1
- package/src/engine/graphics/shaders/SoftOutlineShader.js +0 -111
- package/src/engine/graphics/three/Reflector.d.ts +0 -12
- package/src/engine/graphics/three/Reflector.d.ts.map +0 -1
- package/src/engine/graphics/three/Reflector.js +0 -281
- package/src/engine/graphics/three/Refractor.d.ts +0 -11
- package/src/engine/graphics/three/Refractor.d.ts.map +0 -1
- package/src/engine/graphics/three/Refractor.js +0 -352
- package/src/engine/navigation/ecs/components/PathFinder.d.ts +0 -14
- package/src/engine/navigation/ecs/components/PathFinder.d.ts.map +0 -1
- package/src/engine/navigation/ecs/components/PathFinder.js +0 -11
- package/src/view/elements/navigation/NavigationMenu.d.ts +0 -13
- package/src/view/elements/navigation/NavigationMenu.d.ts.map +0 -1
- package/src/view/elements/navigation/NavigationMenu.js +0 -27
- /package/src/core/collection/set/{Set.d.ts → ArraySet.d.ts} +0 -0
|
@@ -1,3179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Rich Tibbett / https://github.com/richtr
|
|
3
|
-
* @author mrdoob / http://mrdoob.com/
|
|
4
|
-
* @author Tony Parisi / http://www.tonyparisi.com/
|
|
5
|
-
* @author Takahiro / https://github.com/takahirox
|
|
6
|
-
* @author Don McCurdy / https://www.donmccurdy.com
|
|
7
|
-
*/
|
|
8
|
-
import * as THREE from 'three';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function GLTFLoader(manager) {
|
|
12
|
-
|
|
13
|
-
this.manager = (manager !== undefined) ? manager : THREE.DefaultLoadingManager;
|
|
14
|
-
this.dracoLoader = null;
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
GLTFLoader.prototype = {
|
|
19
|
-
|
|
20
|
-
constructor: GLTFLoader,
|
|
21
|
-
|
|
22
|
-
crossOrigin: 'anonymous',
|
|
23
|
-
|
|
24
|
-
load: function (url, onLoad, onProgress, onError) {
|
|
25
|
-
|
|
26
|
-
const scope = this;
|
|
27
|
-
|
|
28
|
-
const path = this.path !== undefined ? this.path : THREE.LoaderUtils.extractUrlBase(url);
|
|
29
|
-
|
|
30
|
-
const loader = new THREE.FileLoader(scope.manager);
|
|
31
|
-
|
|
32
|
-
loader.setResponseType('arraybuffer');
|
|
33
|
-
|
|
34
|
-
loader.load(url, function (data) {
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
|
|
38
|
-
scope.parse(data, path, onLoad, onError);
|
|
39
|
-
|
|
40
|
-
} catch (e) {
|
|
41
|
-
|
|
42
|
-
if (onError !== undefined) {
|
|
43
|
-
|
|
44
|
-
onError(e);
|
|
45
|
-
|
|
46
|
-
} else {
|
|
47
|
-
|
|
48
|
-
throw e;
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}, onProgress, onError);
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
setCrossOrigin: function (value) {
|
|
59
|
-
|
|
60
|
-
this.crossOrigin = value;
|
|
61
|
-
return this;
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
setPath: function (value) {
|
|
66
|
-
|
|
67
|
-
this.path = value;
|
|
68
|
-
return this;
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
setDRACOLoader: function (dracoLoader) {
|
|
73
|
-
|
|
74
|
-
this.dracoLoader = dracoLoader;
|
|
75
|
-
return this;
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
parse: function (data, path, onLoad, onError) {
|
|
80
|
-
|
|
81
|
-
let content;
|
|
82
|
-
const extensions = {};
|
|
83
|
-
|
|
84
|
-
if (typeof data === 'string') {
|
|
85
|
-
|
|
86
|
-
content = data;
|
|
87
|
-
|
|
88
|
-
} else {
|
|
89
|
-
|
|
90
|
-
const magic = THREE.LoaderUtils.decodeText(new Uint8Array(data, 0, 4));
|
|
91
|
-
|
|
92
|
-
if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
|
|
96
|
-
extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
|
|
97
|
-
|
|
98
|
-
} catch (error) {
|
|
99
|
-
|
|
100
|
-
if (onError) onError(error);
|
|
101
|
-
return;
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
content = extensions[EXTENSIONS.KHR_BINARY_GLTF].content;
|
|
106
|
-
|
|
107
|
-
} else {
|
|
108
|
-
|
|
109
|
-
content = THREE.LoaderUtils.decodeText(new Uint8Array(data));
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const json = JSON.parse(content);
|
|
116
|
-
|
|
117
|
-
if (json.asset === undefined || json.asset.version[0] < 2) {
|
|
118
|
-
|
|
119
|
-
if (onError) onError(new Error('THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported. Use LegacyGLTFLoader instead.'));
|
|
120
|
-
return;
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (json.extensionsUsed) {
|
|
125
|
-
|
|
126
|
-
for (let i = 0; i < json.extensionsUsed.length; ++i) {
|
|
127
|
-
|
|
128
|
-
const extensionName = json.extensionsUsed[i];
|
|
129
|
-
const extensionsRequired = json.extensionsRequired || [];
|
|
130
|
-
|
|
131
|
-
switch (extensionName) {
|
|
132
|
-
|
|
133
|
-
case EXTENSIONS.KHR_LIGHTS_PUNCTUAL:
|
|
134
|
-
extensions[extensionName] = new GLTFLightsExtension(json);
|
|
135
|
-
break;
|
|
136
|
-
|
|
137
|
-
case EXTENSIONS.KHR_MATERIALS_UNLIT:
|
|
138
|
-
extensions[extensionName] = new GLTFMaterialsUnlitExtension(json);
|
|
139
|
-
break;
|
|
140
|
-
|
|
141
|
-
case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
|
|
142
|
-
extensions[extensionName] = new GLTFMaterialsPbrSpecularGlossinessExtension();
|
|
143
|
-
break;
|
|
144
|
-
|
|
145
|
-
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
|
146
|
-
extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
|
|
147
|
-
break;
|
|
148
|
-
|
|
149
|
-
case EXTENSIONS.MSFT_TEXTURE_DDS:
|
|
150
|
-
extensions[EXTENSIONS.MSFT_TEXTURE_DDS] = new GLTFTextureDDSExtension();
|
|
151
|
-
break;
|
|
152
|
-
|
|
153
|
-
default:
|
|
154
|
-
|
|
155
|
-
if (extensionsRequired.indexOf(extensionName) >= 0) {
|
|
156
|
-
|
|
157
|
-
console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".');
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const parser = new GLTFParser(json, extensions, {
|
|
168
|
-
|
|
169
|
-
path: path || this.path || '',
|
|
170
|
-
crossOrigin: this.crossOrigin,
|
|
171
|
-
manager: this.manager
|
|
172
|
-
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
parser.parse(function (scene, scenes, cameras, animations, json) {
|
|
176
|
-
|
|
177
|
-
const glTF = {
|
|
178
|
-
scene: scene,
|
|
179
|
-
scenes: scenes,
|
|
180
|
-
cameras: cameras,
|
|
181
|
-
animations: animations,
|
|
182
|
-
asset: json.asset,
|
|
183
|
-
parser: parser,
|
|
184
|
-
userData: {}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
addUnknownExtensionsToUserData(extensions, glTF, json);
|
|
188
|
-
|
|
189
|
-
onLoad(glTF);
|
|
190
|
-
|
|
191
|
-
}, onError);
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
/* GLTFREGISTRY */
|
|
198
|
-
|
|
199
|
-
function GLTFRegistry() {
|
|
200
|
-
|
|
201
|
-
let objects = {};
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
|
|
205
|
-
get: function (key) {
|
|
206
|
-
|
|
207
|
-
return objects[key];
|
|
208
|
-
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
add: function (key, object) {
|
|
212
|
-
|
|
213
|
-
objects[key] = object;
|
|
214
|
-
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
remove: function (key) {
|
|
218
|
-
|
|
219
|
-
delete objects[key];
|
|
220
|
-
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
removeAll: function () {
|
|
224
|
-
|
|
225
|
-
objects = {};
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/*********************************/
|
|
234
|
-
/********** EXTENSIONS ***********/
|
|
235
|
-
/*********************************/
|
|
236
|
-
|
|
237
|
-
const EXTENSIONS = {
|
|
238
|
-
KHR_BINARY_GLTF: 'KHR_binary_glTF',
|
|
239
|
-
KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
|
|
240
|
-
KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
|
|
241
|
-
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
|
|
242
|
-
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
|
|
243
|
-
MSFT_TEXTURE_DDS: 'MSFT_texture_dds'
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* DDS Texture Extension
|
|
248
|
-
*
|
|
249
|
-
* Specification:
|
|
250
|
-
* https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds
|
|
251
|
-
*
|
|
252
|
-
*/
|
|
253
|
-
function GLTFTextureDDSExtension() {
|
|
254
|
-
|
|
255
|
-
if (!THREE.DDSLoader) {
|
|
256
|
-
|
|
257
|
-
throw new Error('THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader');
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
this.name = EXTENSIONS.MSFT_TEXTURE_DDS;
|
|
262
|
-
this.ddsLoader = new THREE.DDSLoader();
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Lights Extension
|
|
268
|
-
*
|
|
269
|
-
* Specification: PENDING
|
|
270
|
-
*/
|
|
271
|
-
function GLTFLightsExtension(json) {
|
|
272
|
-
|
|
273
|
-
this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
|
|
274
|
-
|
|
275
|
-
this.lights = [];
|
|
276
|
-
|
|
277
|
-
const extension = (json.extensions && json.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL]) || {};
|
|
278
|
-
const lightDefs = extension.lights || [];
|
|
279
|
-
|
|
280
|
-
for (let i = 0; i < lightDefs.length; i++) {
|
|
281
|
-
|
|
282
|
-
const lightDef = lightDefs[i];
|
|
283
|
-
let lightNode;
|
|
284
|
-
|
|
285
|
-
const color = new THREE.Color(0xffffff);
|
|
286
|
-
if (lightDef.color !== undefined) color.fromArray(lightDef.color);
|
|
287
|
-
|
|
288
|
-
const range = lightDef.range !== undefined ? lightDef.range : 0;
|
|
289
|
-
|
|
290
|
-
switch (lightDef.type) {
|
|
291
|
-
|
|
292
|
-
case 'directional':
|
|
293
|
-
lightNode = new THREE.DirectionalLight(color);
|
|
294
|
-
lightNode.target.position.set(0, 0, 1);
|
|
295
|
-
lightNode.add(lightNode.target);
|
|
296
|
-
break;
|
|
297
|
-
|
|
298
|
-
case 'point':
|
|
299
|
-
lightNode = new THREE.PointLight(color);
|
|
300
|
-
lightNode.distance = range;
|
|
301
|
-
break;
|
|
302
|
-
|
|
303
|
-
case 'spot':
|
|
304
|
-
lightNode = new THREE.SpotLight(color);
|
|
305
|
-
lightNode.distance = range;
|
|
306
|
-
// Handle spotlight properties.
|
|
307
|
-
lightDef.spot = lightDef.spot || {};
|
|
308
|
-
lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
|
|
309
|
-
lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
|
|
310
|
-
lightNode.angle = lightDef.spot.outerConeAngle;
|
|
311
|
-
lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
|
|
312
|
-
lightNode.target.position.set(0, 0, 1);
|
|
313
|
-
lightNode.add(lightNode.target);
|
|
314
|
-
break;
|
|
315
|
-
|
|
316
|
-
default:
|
|
317
|
-
throw new Error('THREE.GLTFLoader: Unexpected light type, "' + lightDef.type + '".');
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
lightNode.decay = 2;
|
|
322
|
-
|
|
323
|
-
if (lightDef.intensity !== undefined) lightNode.intensity = lightDef.intensity;
|
|
324
|
-
|
|
325
|
-
lightNode.name = lightDef.name || ('light_' + i);
|
|
326
|
-
|
|
327
|
-
this.lights.push(lightNode);
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Unlit Materials Extension (pending)
|
|
335
|
-
*
|
|
336
|
-
* PR: https://github.com/KhronosGroup/glTF/pull/1163
|
|
337
|
-
*/
|
|
338
|
-
function GLTFMaterialsUnlitExtension(json) {
|
|
339
|
-
|
|
340
|
-
this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
GLTFMaterialsUnlitExtension.prototype.getMaterialType = function (material) {
|
|
345
|
-
|
|
346
|
-
return THREE.MeshBasicMaterial;
|
|
347
|
-
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
GLTFMaterialsUnlitExtension.prototype.extendParams = function (materialParams, material, parser) {
|
|
351
|
-
|
|
352
|
-
const pending = [];
|
|
353
|
-
|
|
354
|
-
materialParams.color = new THREE.Color(1.0, 1.0, 1.0);
|
|
355
|
-
materialParams.opacity = 1.0;
|
|
356
|
-
|
|
357
|
-
const metallicRoughness = material.pbrMetallicRoughness;
|
|
358
|
-
|
|
359
|
-
if (metallicRoughness) {
|
|
360
|
-
|
|
361
|
-
if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
|
362
|
-
|
|
363
|
-
const array = metallicRoughness.baseColorFactor;
|
|
364
|
-
|
|
365
|
-
materialParams.color.fromArray(array);
|
|
366
|
-
materialParams.opacity = array[3];
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (metallicRoughness.baseColorTexture !== undefined) {
|
|
371
|
-
|
|
372
|
-
pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture.index));
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
return Promise.all(pending);
|
|
379
|
-
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
/* BINARY EXTENSION */
|
|
383
|
-
|
|
384
|
-
const BINARY_EXTENSION_BUFFER_NAME = 'binary_glTF';
|
|
385
|
-
const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
|
|
386
|
-
const BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
387
|
-
const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
|
|
388
|
-
|
|
389
|
-
function GLTFBinaryExtension(data) {
|
|
390
|
-
|
|
391
|
-
this.name = EXTENSIONS.KHR_BINARY_GLTF;
|
|
392
|
-
this.content = null;
|
|
393
|
-
this.body = null;
|
|
394
|
-
|
|
395
|
-
const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
|
|
396
|
-
|
|
397
|
-
this.header = {
|
|
398
|
-
magic: THREE.LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
|
|
399
|
-
version: headerView.getUint32(4, true),
|
|
400
|
-
length: headerView.getUint32(8, true)
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
404
|
-
|
|
405
|
-
throw new Error('THREE.GLTFLoader: Unsupported glTF-Binary header.');
|
|
406
|
-
|
|
407
|
-
} else if (this.header.version < 2.0) {
|
|
408
|
-
|
|
409
|
-
throw new Error('THREE.GLTFLoader: Legacy binary file detected. Use LegacyGLTFLoader instead.');
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
|
|
414
|
-
let chunkIndex = 0;
|
|
415
|
-
|
|
416
|
-
while (chunkIndex < chunkView.byteLength) {
|
|
417
|
-
|
|
418
|
-
const chunkLength = chunkView.getUint32(chunkIndex, true);
|
|
419
|
-
chunkIndex += 4;
|
|
420
|
-
|
|
421
|
-
const chunkType = chunkView.getUint32(chunkIndex, true);
|
|
422
|
-
chunkIndex += 4;
|
|
423
|
-
|
|
424
|
-
if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
|
425
|
-
|
|
426
|
-
const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
|
|
427
|
-
this.content = THREE.LoaderUtils.decodeText(contentArray);
|
|
428
|
-
|
|
429
|
-
} else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
|
430
|
-
|
|
431
|
-
const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
|
|
432
|
-
this.body = data.slice(byteOffset, byteOffset + chunkLength);
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// Clients must ignore chunks with unknown types.
|
|
437
|
-
|
|
438
|
-
chunkIndex += chunkLength;
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (this.content === null) {
|
|
443
|
-
|
|
444
|
-
throw new Error('THREE.GLTFLoader: JSON content not found.');
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* DRACO Mesh Compression Extension
|
|
452
|
-
*
|
|
453
|
-
* Specification: https://github.com/KhronosGroup/glTF/pull/874
|
|
454
|
-
*/
|
|
455
|
-
function GLTFDracoMeshCompressionExtension(json, dracoLoader) {
|
|
456
|
-
|
|
457
|
-
if (!dracoLoader) {
|
|
458
|
-
|
|
459
|
-
throw new Error('THREE.GLTFLoader: No DRACOLoader instance provided.');
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
|
|
464
|
-
this.json = json;
|
|
465
|
-
this.dracoLoader = dracoLoader;
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
GLTFDracoMeshCompressionExtension.prototype.decodePrimitive = function (primitive, parser) {
|
|
470
|
-
|
|
471
|
-
const json = this.json;
|
|
472
|
-
const dracoLoader = this.dracoLoader;
|
|
473
|
-
const bufferViewIndex = primitive.extensions[this.name].bufferView;
|
|
474
|
-
const gltfAttributeMap = primitive.extensions[this.name].attributes;
|
|
475
|
-
const threeAttributeMap = {};
|
|
476
|
-
const attributeNormalizedMap = {};
|
|
477
|
-
const attributeTypeMap = {};
|
|
478
|
-
|
|
479
|
-
for (let attributeName in gltfAttributeMap) {
|
|
480
|
-
|
|
481
|
-
if (!(attributeName in ATTRIBUTES)) continue;
|
|
482
|
-
|
|
483
|
-
threeAttributeMap[ATTRIBUTES[attributeName]] = gltfAttributeMap[attributeName];
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
for (attributeName in primitive.attributes) {
|
|
488
|
-
|
|
489
|
-
if (ATTRIBUTES[attributeName] !== undefined && gltfAttributeMap[attributeName] !== undefined) {
|
|
490
|
-
|
|
491
|
-
const accessorDef = json.accessors[primitive.attributes[attributeName]];
|
|
492
|
-
const componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
493
|
-
|
|
494
|
-
attributeTypeMap[ATTRIBUTES[attributeName]] = componentType;
|
|
495
|
-
attributeNormalizedMap[ATTRIBUTES[attributeName]] = accessorDef.normalized === true;
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
return parser.getDependency('bufferView', bufferViewIndex).then(function (bufferView) {
|
|
502
|
-
|
|
503
|
-
return new Promise(function (resolve) {
|
|
504
|
-
|
|
505
|
-
dracoLoader.decodeDracoFile(bufferView, function (geometry) {
|
|
506
|
-
|
|
507
|
-
for (let attributeName in geometry.attributes) {
|
|
508
|
-
|
|
509
|
-
const attribute = geometry.attributes[attributeName];
|
|
510
|
-
const normalized = attributeNormalizedMap[attributeName];
|
|
511
|
-
|
|
512
|
-
if (normalized !== undefined) attribute.normalized = normalized;
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
resolve(geometry);
|
|
517
|
-
|
|
518
|
-
}, threeAttributeMap, attributeTypeMap);
|
|
519
|
-
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Specular-Glossiness Extension
|
|
528
|
-
*
|
|
529
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness
|
|
530
|
-
*/
|
|
531
|
-
function GLTFMaterialsPbrSpecularGlossinessExtension() {
|
|
532
|
-
|
|
533
|
-
return {
|
|
534
|
-
|
|
535
|
-
name: EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,
|
|
536
|
-
|
|
537
|
-
specularGlossinessParams: [
|
|
538
|
-
'color',
|
|
539
|
-
'map',
|
|
540
|
-
'lightMap',
|
|
541
|
-
'lightMapIntensity',
|
|
542
|
-
'aoMap',
|
|
543
|
-
'aoMapIntensity',
|
|
544
|
-
'emissive',
|
|
545
|
-
'emissiveIntensity',
|
|
546
|
-
'emissiveMap',
|
|
547
|
-
'bumpMap',
|
|
548
|
-
'bumpScale',
|
|
549
|
-
'normalMap',
|
|
550
|
-
'displacementMap',
|
|
551
|
-
'displacementScale',
|
|
552
|
-
'displacementBias',
|
|
553
|
-
'specularMap',
|
|
554
|
-
'specular',
|
|
555
|
-
'glossinessMap',
|
|
556
|
-
'glossiness',
|
|
557
|
-
'alphaMap',
|
|
558
|
-
'envMap',
|
|
559
|
-
'envMapIntensity',
|
|
560
|
-
'refractionRatio',
|
|
561
|
-
],
|
|
562
|
-
|
|
563
|
-
getMaterialType: function () {
|
|
564
|
-
|
|
565
|
-
return THREE.ShaderMaterial;
|
|
566
|
-
|
|
567
|
-
},
|
|
568
|
-
|
|
569
|
-
extendParams: function (params, material, parser) {
|
|
570
|
-
|
|
571
|
-
const pbrSpecularGlossiness = material.extensions[this.name];
|
|
572
|
-
|
|
573
|
-
const shader = THREE.ShaderLib['standard'];
|
|
574
|
-
|
|
575
|
-
const uniforms = THREE.UniformsUtils.clone(shader.uniforms);
|
|
576
|
-
|
|
577
|
-
const specularMapParsFragmentChunk = [
|
|
578
|
-
'#ifdef USE_SPECULARMAP',
|
|
579
|
-
' uniform sampler2D specularMap;',
|
|
580
|
-
'#endif'
|
|
581
|
-
].join('\n');
|
|
582
|
-
|
|
583
|
-
const glossinessMapParsFragmentChunk = [
|
|
584
|
-
'#ifdef USE_GLOSSINESSMAP',
|
|
585
|
-
' uniform sampler2D glossinessMap;',
|
|
586
|
-
'#endif'
|
|
587
|
-
].join('\n');
|
|
588
|
-
|
|
589
|
-
const specularMapFragmentChunk = [
|
|
590
|
-
'vec3 specularFactor = specular;',
|
|
591
|
-
'#ifdef USE_SPECULARMAP',
|
|
592
|
-
' vec4 texelSpecular = texture2D( specularMap, vUv );',
|
|
593
|
-
' texelSpecular = sRGBToLinear( texelSpecular );',
|
|
594
|
-
' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture',
|
|
595
|
-
' specularFactor *= texelSpecular.rgb;',
|
|
596
|
-
'#endif'
|
|
597
|
-
].join('\n');
|
|
598
|
-
|
|
599
|
-
const glossinessMapFragmentChunk = [
|
|
600
|
-
'float glossinessFactor = glossiness;',
|
|
601
|
-
'#ifdef USE_GLOSSINESSMAP',
|
|
602
|
-
' vec4 texelGlossiness = texture2D( glossinessMap, vUv );',
|
|
603
|
-
' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture',
|
|
604
|
-
' glossinessFactor *= texelGlossiness.a;',
|
|
605
|
-
'#endif'
|
|
606
|
-
].join('\n');
|
|
607
|
-
|
|
608
|
-
const lightPhysicalFragmentChunk = [
|
|
609
|
-
'PhysicalMaterial material;',
|
|
610
|
-
'material.diffuseColor = diffuseColor.rgb;',
|
|
611
|
-
'material.specularRoughness = clamp( 1.0 - glossinessFactor, 0.04, 1.0 );',
|
|
612
|
-
'material.specularColor = specularFactor.rgb;',
|
|
613
|
-
].join('\n');
|
|
614
|
-
|
|
615
|
-
const fragmentShader = shader.fragmentShader
|
|
616
|
-
.replace('uniform float roughness;', 'uniform vec3 specular;')
|
|
617
|
-
.replace('uniform float metalness;', 'uniform float glossiness;')
|
|
618
|
-
.replace('#include <roughnessmap_pars_fragment>', specularMapParsFragmentChunk)
|
|
619
|
-
.replace('#include <metalnessmap_pars_fragment>', glossinessMapParsFragmentChunk)
|
|
620
|
-
.replace('#include <roughnessmap_fragment>', specularMapFragmentChunk)
|
|
621
|
-
.replace('#include <metalnessmap_fragment>', glossinessMapFragmentChunk)
|
|
622
|
-
.replace('#include <lights_physical_fragment>', lightPhysicalFragmentChunk);
|
|
623
|
-
|
|
624
|
-
delete uniforms.roughness;
|
|
625
|
-
delete uniforms.metalness;
|
|
626
|
-
delete uniforms.roughnessMap;
|
|
627
|
-
delete uniforms.metalnessMap;
|
|
628
|
-
|
|
629
|
-
uniforms.specular = { value: new THREE.Color().setHex(0x111111) };
|
|
630
|
-
uniforms.glossiness = { value: 0.5 };
|
|
631
|
-
uniforms.specularMap = { value: null };
|
|
632
|
-
uniforms.glossinessMap = { value: null };
|
|
633
|
-
|
|
634
|
-
params.vertexShader = shader.vertexShader;
|
|
635
|
-
params.fragmentShader = fragmentShader;
|
|
636
|
-
params.uniforms = uniforms;
|
|
637
|
-
params.defines = { 'STANDARD': '' };
|
|
638
|
-
|
|
639
|
-
params.color = new THREE.Color(1.0, 1.0, 1.0);
|
|
640
|
-
params.opacity = 1.0;
|
|
641
|
-
|
|
642
|
-
const pending = [];
|
|
643
|
-
|
|
644
|
-
if (Array.isArray(pbrSpecularGlossiness.diffuseFactor)) {
|
|
645
|
-
|
|
646
|
-
const array = pbrSpecularGlossiness.diffuseFactor;
|
|
647
|
-
|
|
648
|
-
params.color.fromArray(array);
|
|
649
|
-
params.opacity = array[3];
|
|
650
|
-
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
if (pbrSpecularGlossiness.diffuseTexture !== undefined) {
|
|
654
|
-
|
|
655
|
-
pending.push(parser.assignTexture(params, 'map', pbrSpecularGlossiness.diffuseTexture.index));
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
params.emissive = new THREE.Color(0.0, 0.0, 0.0);
|
|
660
|
-
params.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
|
|
661
|
-
params.specular = new THREE.Color(1.0, 1.0, 1.0);
|
|
662
|
-
|
|
663
|
-
if (Array.isArray(pbrSpecularGlossiness.specularFactor)) {
|
|
664
|
-
|
|
665
|
-
params.specular.fromArray(pbrSpecularGlossiness.specularFactor);
|
|
666
|
-
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
if (pbrSpecularGlossiness.specularGlossinessTexture !== undefined) {
|
|
670
|
-
|
|
671
|
-
const specGlossIndex = pbrSpecularGlossiness.specularGlossinessTexture.index;
|
|
672
|
-
pending.push(parser.assignTexture(params, 'glossinessMap', specGlossIndex));
|
|
673
|
-
pending.push(parser.assignTexture(params, 'specularMap', specGlossIndex));
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
return Promise.all(pending);
|
|
678
|
-
|
|
679
|
-
},
|
|
680
|
-
|
|
681
|
-
createMaterial: function (params) {
|
|
682
|
-
|
|
683
|
-
// setup material properties based on MeshStandardMaterial for Specular-Glossiness
|
|
684
|
-
|
|
685
|
-
const material = new THREE.ShaderMaterial({
|
|
686
|
-
defines: params.defines,
|
|
687
|
-
vertexShader: params.vertexShader,
|
|
688
|
-
fragmentShader: params.fragmentShader,
|
|
689
|
-
uniforms: params.uniforms,
|
|
690
|
-
fog: true,
|
|
691
|
-
lights: true,
|
|
692
|
-
opacity: params.opacity,
|
|
693
|
-
transparent: params.transparent
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
material.isGLTFSpecularGlossinessMaterial = true;
|
|
697
|
-
|
|
698
|
-
material.color = params.color;
|
|
699
|
-
|
|
700
|
-
material.map = params.map === undefined ? null : params.map;
|
|
701
|
-
|
|
702
|
-
material.lightMap = null;
|
|
703
|
-
material.lightMapIntensity = 1.0;
|
|
704
|
-
|
|
705
|
-
material.aoMap = params.aoMap === undefined ? null : params.aoMap;
|
|
706
|
-
material.aoMapIntensity = 1.0;
|
|
707
|
-
|
|
708
|
-
material.emissive = params.emissive;
|
|
709
|
-
material.emissiveIntensity = 1.0;
|
|
710
|
-
material.emissiveMap = params.emissiveMap === undefined ? null : params.emissiveMap;
|
|
711
|
-
|
|
712
|
-
material.bumpMap = params.bumpMap === undefined ? null : params.bumpMap;
|
|
713
|
-
material.bumpScale = 1;
|
|
714
|
-
|
|
715
|
-
material.normalMap = params.normalMap === undefined ? null : params.normalMap;
|
|
716
|
-
if (params.normalScale) material.normalScale = params.normalScale;
|
|
717
|
-
|
|
718
|
-
material.displacementMap = null;
|
|
719
|
-
material.displacementScale = 1;
|
|
720
|
-
material.displacementBias = 0;
|
|
721
|
-
|
|
722
|
-
material.specularMap = params.specularMap === undefined ? null : params.specularMap;
|
|
723
|
-
material.specular = params.specular;
|
|
724
|
-
|
|
725
|
-
material.glossinessMap = params.glossinessMap === undefined ? null : params.glossinessMap;
|
|
726
|
-
material.glossiness = params.glossiness;
|
|
727
|
-
|
|
728
|
-
material.alphaMap = null;
|
|
729
|
-
|
|
730
|
-
material.envMap = params.envMap === undefined ? null : params.envMap;
|
|
731
|
-
material.envMapIntensity = 1.0;
|
|
732
|
-
|
|
733
|
-
material.refractionRatio = 0.98;
|
|
734
|
-
|
|
735
|
-
material.extensions.derivatives = true;
|
|
736
|
-
|
|
737
|
-
return material;
|
|
738
|
-
|
|
739
|
-
},
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
* Clones a GLTFSpecularGlossinessMaterial instance. The ShaderMaterial.copy() method can
|
|
743
|
-
* copy only properties it knows about or inherits, and misses many properties that would
|
|
744
|
-
* normally be defined by MeshStandardMaterial.
|
|
745
|
-
*
|
|
746
|
-
* This method allows GLTFSpecularGlossinessMaterials to be cloned in the process of
|
|
747
|
-
* loading a glTF model, but cloning later (e.g. by the user) would require these changes
|
|
748
|
-
* AND also updating `.onBeforeRender` on the parent mesh.
|
|
749
|
-
*
|
|
750
|
-
* @param {THREE.ShaderMaterial} source
|
|
751
|
-
* @return {THREE.ShaderMaterial}
|
|
752
|
-
*/
|
|
753
|
-
cloneMaterial: function (source) {
|
|
754
|
-
|
|
755
|
-
const target = source.clone();
|
|
756
|
-
|
|
757
|
-
target.isGLTFSpecularGlossinessMaterial = true;
|
|
758
|
-
|
|
759
|
-
const params = this.specularGlossinessParams;
|
|
760
|
-
|
|
761
|
-
let i = 0;
|
|
762
|
-
const il = params.length;
|
|
763
|
-
for (; i < il; i++) {
|
|
764
|
-
|
|
765
|
-
target[params[i]] = source[params[i]];
|
|
766
|
-
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
return target;
|
|
770
|
-
|
|
771
|
-
},
|
|
772
|
-
|
|
773
|
-
// Here's based on refreshUniformsCommon() and refreshUniformsStandard() in WebGLRenderer.
|
|
774
|
-
refreshUniforms: function (renderer, scene, camera, geometry, material, group) {
|
|
775
|
-
|
|
776
|
-
if (material.isGLTFSpecularGlossinessMaterial !== true) {
|
|
777
|
-
|
|
778
|
-
return;
|
|
779
|
-
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
const uniforms = material.uniforms;
|
|
783
|
-
const defines = material.defines;
|
|
784
|
-
|
|
785
|
-
uniforms.opacity.value = material.opacity;
|
|
786
|
-
|
|
787
|
-
uniforms.diffuse.value.copy(material.color);
|
|
788
|
-
uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
|
|
789
|
-
|
|
790
|
-
uniforms.map.value = material.map;
|
|
791
|
-
uniforms.specularMap.value = material.specularMap;
|
|
792
|
-
uniforms.alphaMap.value = material.alphaMap;
|
|
793
|
-
|
|
794
|
-
uniforms.lightMap.value = material.lightMap;
|
|
795
|
-
uniforms.lightMapIntensity.value = material.lightMapIntensity;
|
|
796
|
-
|
|
797
|
-
uniforms.aoMap.value = material.aoMap;
|
|
798
|
-
uniforms.aoMapIntensity.value = material.aoMapIntensity;
|
|
799
|
-
|
|
800
|
-
// uv repeat and offset setting priorities
|
|
801
|
-
// 1. color map
|
|
802
|
-
// 2. specular map
|
|
803
|
-
// 3. normal map
|
|
804
|
-
// 4. bump map
|
|
805
|
-
// 5. alpha map
|
|
806
|
-
// 6. emissive map
|
|
807
|
-
|
|
808
|
-
let uvScaleMap;
|
|
809
|
-
|
|
810
|
-
if (material.map) {
|
|
811
|
-
|
|
812
|
-
uvScaleMap = material.map;
|
|
813
|
-
|
|
814
|
-
} else if (material.specularMap) {
|
|
815
|
-
|
|
816
|
-
uvScaleMap = material.specularMap;
|
|
817
|
-
|
|
818
|
-
} else if (material.displacementMap) {
|
|
819
|
-
|
|
820
|
-
uvScaleMap = material.displacementMap;
|
|
821
|
-
|
|
822
|
-
} else if (material.normalMap) {
|
|
823
|
-
|
|
824
|
-
uvScaleMap = material.normalMap;
|
|
825
|
-
|
|
826
|
-
} else if (material.bumpMap) {
|
|
827
|
-
|
|
828
|
-
uvScaleMap = material.bumpMap;
|
|
829
|
-
|
|
830
|
-
} else if (material.glossinessMap) {
|
|
831
|
-
|
|
832
|
-
uvScaleMap = material.glossinessMap;
|
|
833
|
-
|
|
834
|
-
} else if (material.alphaMap) {
|
|
835
|
-
|
|
836
|
-
uvScaleMap = material.alphaMap;
|
|
837
|
-
|
|
838
|
-
} else if (material.emissiveMap) {
|
|
839
|
-
|
|
840
|
-
uvScaleMap = material.emissiveMap;
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
if (uvScaleMap !== undefined) {
|
|
845
|
-
|
|
846
|
-
// backwards compatibility
|
|
847
|
-
if (uvScaleMap.isWebGLRenderTarget) {
|
|
848
|
-
|
|
849
|
-
uvScaleMap = uvScaleMap.texture;
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
if (uvScaleMap.matrixAutoUpdate === true) {
|
|
854
|
-
|
|
855
|
-
uvScaleMap.updateMatrix();
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
uniforms.uvTransform.value.copy(uvScaleMap.matrix);
|
|
860
|
-
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
uniforms.envMap.value = material.envMap;
|
|
864
|
-
uniforms.envMapIntensity.value = material.envMapIntensity;
|
|
865
|
-
uniforms.flipEnvMap.value = (material.envMap && material.envMap.isCubeTexture) ? -1 : 1;
|
|
866
|
-
|
|
867
|
-
uniforms.refractionRatio.value = material.refractionRatio;
|
|
868
|
-
|
|
869
|
-
uniforms.specular.value.copy(material.specular);
|
|
870
|
-
uniforms.glossiness.value = material.glossiness;
|
|
871
|
-
|
|
872
|
-
uniforms.glossinessMap.value = material.glossinessMap;
|
|
873
|
-
|
|
874
|
-
uniforms.emissiveMap.value = material.emissiveMap;
|
|
875
|
-
uniforms.bumpMap.value = material.bumpMap;
|
|
876
|
-
uniforms.normalMap.value = material.normalMap;
|
|
877
|
-
|
|
878
|
-
uniforms.displacementMap.value = material.displacementMap;
|
|
879
|
-
uniforms.displacementScale.value = material.displacementScale;
|
|
880
|
-
uniforms.displacementBias.value = material.displacementBias;
|
|
881
|
-
|
|
882
|
-
if (uniforms.glossinessMap.value !== null && defines.USE_GLOSSINESSMAP === undefined) {
|
|
883
|
-
|
|
884
|
-
defines.USE_GLOSSINESSMAP = '';
|
|
885
|
-
// set USE_ROUGHNESSMAP to enable vUv
|
|
886
|
-
defines.USE_ROUGHNESSMAP = '';
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
if (uniforms.glossinessMap.value === null && defines.USE_GLOSSINESSMAP !== undefined) {
|
|
891
|
-
|
|
892
|
-
delete defines.USE_GLOSSINESSMAP;
|
|
893
|
-
delete defines.USE_ROUGHNESSMAP;
|
|
894
|
-
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
/*********************************/
|
|
904
|
-
/********** INTERPOLATION ********/
|
|
905
|
-
/*********************************/
|
|
906
|
-
|
|
907
|
-
// Spline Interpolation
|
|
908
|
-
// Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
|
|
909
|
-
function GLTFCubicSplineInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
910
|
-
|
|
911
|
-
THREE.Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
|
|
912
|
-
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
GLTFCubicSplineInterpolant.prototype = Object.create(THREE.Interpolant.prototype);
|
|
916
|
-
GLTFCubicSplineInterpolant.prototype.constructor = GLTFCubicSplineInterpolant;
|
|
917
|
-
|
|
918
|
-
GLTFCubicSplineInterpolant.prototype.copySampleValue_ = function (index) {
|
|
919
|
-
|
|
920
|
-
// Copies a sample value to the result buffer. See description of glTF
|
|
921
|
-
// CUBICSPLINE values layout in interpolate_() function below.
|
|
922
|
-
|
|
923
|
-
const result = this.resultBuffer,
|
|
924
|
-
values = this.sampleValues,
|
|
925
|
-
valueSize = this.valueSize,
|
|
926
|
-
offset = index * valueSize * 3 + valueSize;
|
|
927
|
-
|
|
928
|
-
for (let i = 0; i !== valueSize; i++) {
|
|
929
|
-
|
|
930
|
-
result[i] = values[offset + i];
|
|
931
|
-
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
return result;
|
|
935
|
-
|
|
936
|
-
};
|
|
937
|
-
|
|
938
|
-
GLTFCubicSplineInterpolant.prototype.beforeStart_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
|
|
939
|
-
|
|
940
|
-
GLTFCubicSplineInterpolant.prototype.afterEnd_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
|
|
941
|
-
|
|
942
|
-
GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
|
|
943
|
-
|
|
944
|
-
const result = this.resultBuffer;
|
|
945
|
-
const values = this.sampleValues;
|
|
946
|
-
const stride = this.valueSize;
|
|
947
|
-
|
|
948
|
-
const stride2 = stride * 2;
|
|
949
|
-
const stride3 = stride * 3;
|
|
950
|
-
|
|
951
|
-
const td = t1 - t0;
|
|
952
|
-
|
|
953
|
-
const p = (t - t0) / td;
|
|
954
|
-
const pp = p * p;
|
|
955
|
-
const ppp = pp * p;
|
|
956
|
-
|
|
957
|
-
const offset1 = i1 * stride3;
|
|
958
|
-
const offset0 = offset1 - stride3;
|
|
959
|
-
|
|
960
|
-
const s0 = 2 * ppp - 3 * pp + 1;
|
|
961
|
-
const s1 = ppp - 2 * pp + p;
|
|
962
|
-
const s2 = -2 * ppp + 3 * pp;
|
|
963
|
-
const s3 = ppp - pp;
|
|
964
|
-
|
|
965
|
-
// Layout of keyframe output values for CUBICSPLINE animations:
|
|
966
|
-
// [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
|
|
967
|
-
for (let i = 0; i !== stride; i++) {
|
|
968
|
-
|
|
969
|
-
const p0 = values[offset0 + i + stride]; // splineVertex_k
|
|
970
|
-
const m0 = values[offset0 + i + stride2] * td; // outTangent_k * (t_k+1 - t_k)
|
|
971
|
-
const p1 = values[offset1 + i + stride]; // splineVertex_k+1
|
|
972
|
-
const m1 = values[offset1 + i] * td; // inTangent_k+1 * (t_k+1 - t_k)
|
|
973
|
-
|
|
974
|
-
result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
|
|
975
|
-
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
return result;
|
|
979
|
-
|
|
980
|
-
};
|
|
981
|
-
|
|
982
|
-
/*********************************/
|
|
983
|
-
/********** INTERNALS ************/
|
|
984
|
-
/*********************************/
|
|
985
|
-
|
|
986
|
-
/* CONSTANTS */
|
|
987
|
-
|
|
988
|
-
const WEBGL_CONSTANTS = {
|
|
989
|
-
FLOAT: 5126,
|
|
990
|
-
//FLOAT_MAT2: 35674,
|
|
991
|
-
FLOAT_MAT3: 35675,
|
|
992
|
-
FLOAT_MAT4: 35676,
|
|
993
|
-
FLOAT_VEC2: 35664,
|
|
994
|
-
FLOAT_VEC3: 35665,
|
|
995
|
-
FLOAT_VEC4: 35666,
|
|
996
|
-
LINEAR: 9729,
|
|
997
|
-
REPEAT: 10497,
|
|
998
|
-
SAMPLER_2D: 35678,
|
|
999
|
-
POINTS: 0,
|
|
1000
|
-
LINES: 1,
|
|
1001
|
-
LINE_LOOP: 2,
|
|
1002
|
-
LINE_STRIP: 3,
|
|
1003
|
-
TRIANGLES: 4,
|
|
1004
|
-
TRIANGLE_STRIP: 5,
|
|
1005
|
-
TRIANGLE_FAN: 6,
|
|
1006
|
-
UNSIGNED_BYTE: 5121,
|
|
1007
|
-
UNSIGNED_SHORT: 5123
|
|
1008
|
-
};
|
|
1009
|
-
|
|
1010
|
-
const WEBGL_TYPE = {
|
|
1011
|
-
5126: Number,
|
|
1012
|
-
//35674: THREE.Matrix2,
|
|
1013
|
-
35675: THREE.Matrix3,
|
|
1014
|
-
35676: THREE.Matrix4,
|
|
1015
|
-
35664: THREE.Vector2,
|
|
1016
|
-
35665: THREE.Vector3,
|
|
1017
|
-
35666: THREE.Vector4,
|
|
1018
|
-
35678: THREE.Texture
|
|
1019
|
-
};
|
|
1020
|
-
|
|
1021
|
-
const WEBGL_COMPONENT_TYPES = {
|
|
1022
|
-
5120: Int8Array,
|
|
1023
|
-
5121: Uint8Array,
|
|
1024
|
-
5122: Int16Array,
|
|
1025
|
-
5123: Uint16Array,
|
|
1026
|
-
5125: Uint32Array,
|
|
1027
|
-
5126: Float32Array
|
|
1028
|
-
};
|
|
1029
|
-
|
|
1030
|
-
const WEBGL_FILTERS = {
|
|
1031
|
-
9728: THREE.NearestFilter,
|
|
1032
|
-
9729: THREE.LinearFilter,
|
|
1033
|
-
9984: THREE.NearestMipMapNearestFilter,
|
|
1034
|
-
9985: THREE.LinearMipMapNearestFilter,
|
|
1035
|
-
9986: THREE.NearestMipMapLinearFilter,
|
|
1036
|
-
9987: THREE.LinearMipMapLinearFilter
|
|
1037
|
-
};
|
|
1038
|
-
|
|
1039
|
-
const WEBGL_WRAPPINGS = {
|
|
1040
|
-
33071: THREE.ClampToEdgeWrapping,
|
|
1041
|
-
33648: THREE.MirroredRepeatWrapping,
|
|
1042
|
-
10497: THREE.RepeatWrapping
|
|
1043
|
-
};
|
|
1044
|
-
|
|
1045
|
-
const WEBGL_SIDES = {
|
|
1046
|
-
1028: THREE.BackSide, // Culling front
|
|
1047
|
-
1029: THREE.FrontSide // Culling back
|
|
1048
|
-
//1032: THREE.NoSide // Culling front and back, what to do?
|
|
1049
|
-
};
|
|
1050
|
-
|
|
1051
|
-
const WEBGL_DEPTH_FUNCS = {
|
|
1052
|
-
512: THREE.NeverDepth,
|
|
1053
|
-
513: THREE.LessDepth,
|
|
1054
|
-
514: THREE.EqualDepth,
|
|
1055
|
-
515: THREE.LessEqualDepth,
|
|
1056
|
-
516: THREE.GreaterEqualDepth,
|
|
1057
|
-
517: THREE.NotEqualDepth,
|
|
1058
|
-
518: THREE.GreaterEqualDepth,
|
|
1059
|
-
519: THREE.AlwaysDepth
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
const WEBGL_BLEND_EQUATIONS = {
|
|
1063
|
-
32774: THREE.AddEquation,
|
|
1064
|
-
32778: THREE.SubtractEquation,
|
|
1065
|
-
32779: THREE.ReverseSubtractEquation
|
|
1066
|
-
};
|
|
1067
|
-
|
|
1068
|
-
const WEBGL_BLEND_FUNCS = {
|
|
1069
|
-
0: THREE.ZeroFactor,
|
|
1070
|
-
1: THREE.OneFactor,
|
|
1071
|
-
768: THREE.SrcColorFactor,
|
|
1072
|
-
769: THREE.OneMinusSrcColorFactor,
|
|
1073
|
-
770: THREE.SrcAlphaFactor,
|
|
1074
|
-
771: THREE.OneMinusSrcAlphaFactor,
|
|
1075
|
-
772: THREE.DstAlphaFactor,
|
|
1076
|
-
773: THREE.OneMinusDstAlphaFactor,
|
|
1077
|
-
774: THREE.DstColorFactor,
|
|
1078
|
-
775: THREE.OneMinusDstColorFactor,
|
|
1079
|
-
776: THREE.SrcAlphaSaturateFactor
|
|
1080
|
-
// The followings are not supported by Three.js yet
|
|
1081
|
-
//32769: CONSTANT_COLOR,
|
|
1082
|
-
//32770: ONE_MINUS_CONSTANT_COLOR,
|
|
1083
|
-
//32771: CONSTANT_ALPHA,
|
|
1084
|
-
//32772: ONE_MINUS_CONSTANT_COLOR
|
|
1085
|
-
};
|
|
1086
|
-
|
|
1087
|
-
const WEBGL_TYPE_SIZES = {
|
|
1088
|
-
'SCALAR': 1,
|
|
1089
|
-
'VEC2': 2,
|
|
1090
|
-
'VEC3': 3,
|
|
1091
|
-
'VEC4': 4,
|
|
1092
|
-
'MAT2': 4,
|
|
1093
|
-
'MAT3': 9,
|
|
1094
|
-
'MAT4': 16
|
|
1095
|
-
};
|
|
1096
|
-
|
|
1097
|
-
const ATTRIBUTES = {
|
|
1098
|
-
POSITION: 'position',
|
|
1099
|
-
NORMAL: 'normal',
|
|
1100
|
-
TEXCOORD_0: 'uv',
|
|
1101
|
-
TEXCOORD0: 'uv', // deprecated
|
|
1102
|
-
TEXCOORD: 'uv', // deprecated
|
|
1103
|
-
TEXCOORD_1: 'uv2',
|
|
1104
|
-
COLOR_0: 'color',
|
|
1105
|
-
COLOR0: 'color', // deprecated
|
|
1106
|
-
COLOR: 'color', // deprecated
|
|
1107
|
-
WEIGHTS_0: 'skinWeight',
|
|
1108
|
-
WEIGHT: 'skinWeight', // deprecated
|
|
1109
|
-
JOINTS_0: 'skinIndex',
|
|
1110
|
-
JOINT: 'skinIndex' // deprecated
|
|
1111
|
-
};
|
|
1112
|
-
|
|
1113
|
-
const PATH_PROPERTIES = {
|
|
1114
|
-
scale: 'scale',
|
|
1115
|
-
translation: 'position',
|
|
1116
|
-
rotation: 'quaternion',
|
|
1117
|
-
weights: 'morphTargetInfluences'
|
|
1118
|
-
};
|
|
1119
|
-
|
|
1120
|
-
const INTERPOLATION = {
|
|
1121
|
-
CUBICSPLINE: THREE.InterpolateSmooth, // We use custom interpolation GLTFCubicSplineInterpolation for CUBICSPLINE.
|
|
1122
|
-
// KeyframeTrack.optimize() can't handle glTF Cubic Spline output values layout,
|
|
1123
|
-
// using THREE.InterpolateSmooth for KeyframeTrack instantiation to prevent optimization.
|
|
1124
|
-
// See KeyframeTrack.optimize() for the detail.
|
|
1125
|
-
LINEAR: THREE.InterpolateLinear,
|
|
1126
|
-
STEP: THREE.InterpolateDiscrete
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
const STATES_ENABLES = {
|
|
1130
|
-
2884: 'CULL_FACE',
|
|
1131
|
-
2929: 'DEPTH_TEST',
|
|
1132
|
-
3042: 'BLEND',
|
|
1133
|
-
3089: 'SCISSOR_TEST',
|
|
1134
|
-
32823: 'POLYGON_OFFSET_FILL',
|
|
1135
|
-
32926: 'SAMPLE_ALPHA_TO_COVERAGE'
|
|
1136
|
-
};
|
|
1137
|
-
|
|
1138
|
-
const ALPHA_MODES = {
|
|
1139
|
-
OPAQUE: 'OPAQUE',
|
|
1140
|
-
MASK: 'MASK',
|
|
1141
|
-
BLEND: 'BLEND'
|
|
1142
|
-
};
|
|
1143
|
-
|
|
1144
|
-
/* UTILITY FUNCTIONS */
|
|
1145
|
-
|
|
1146
|
-
function resolveURL(url, path) {
|
|
1147
|
-
|
|
1148
|
-
// Invalid URL
|
|
1149
|
-
if (typeof url !== 'string' || url === '') return '';
|
|
1150
|
-
|
|
1151
|
-
// Absolute URL http://,https://,//
|
|
1152
|
-
if (/^(https?:)?\/\//i.test(url)) return url;
|
|
1153
|
-
|
|
1154
|
-
// Data URI
|
|
1155
|
-
if (/^data:.*,.*$/i.test(url)) return url;
|
|
1156
|
-
|
|
1157
|
-
// Blob URL
|
|
1158
|
-
if (/^blob:.*$/i.test(url)) return url;
|
|
1159
|
-
|
|
1160
|
-
// Relative URL
|
|
1161
|
-
return path + url;
|
|
1162
|
-
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
/**
|
|
1166
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
|
|
1167
|
-
*/
|
|
1168
|
-
function createDefaultMaterial() {
|
|
1169
|
-
|
|
1170
|
-
return new THREE.MeshStandardMaterial({
|
|
1171
|
-
color: 0xFFFFFF,
|
|
1172
|
-
emissive: 0x000000,
|
|
1173
|
-
metalness: 1,
|
|
1174
|
-
roughness: 1,
|
|
1175
|
-
transparent: false,
|
|
1176
|
-
depthTest: true,
|
|
1177
|
-
side: THREE.FrontSide
|
|
1178
|
-
});
|
|
1179
|
-
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
|
|
1183
|
-
|
|
1184
|
-
// Add unknown glTF extensions to an object's userData.
|
|
1185
|
-
|
|
1186
|
-
for (let name in objectDef.extensions) {
|
|
1187
|
-
|
|
1188
|
-
if (knownExtensions[name] === undefined) {
|
|
1189
|
-
|
|
1190
|
-
object.userData.gltfExtensions = object.userData.gltfExtensions || {};
|
|
1191
|
-
object.userData.gltfExtensions[name] = objectDef.extensions[name];
|
|
1192
|
-
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
/**
|
|
1200
|
-
* @param {THREE.Object3D|THREE.Material|THREE.BufferGeometry} object
|
|
1201
|
-
* @param {GLTF.definition} def
|
|
1202
|
-
*/
|
|
1203
|
-
function assignExtrasToUserData(object, gltfDef) {
|
|
1204
|
-
|
|
1205
|
-
if (gltfDef.extras !== undefined) {
|
|
1206
|
-
|
|
1207
|
-
if (typeof gltfDef.extras === 'object') {
|
|
1208
|
-
|
|
1209
|
-
object.userData = gltfDef.extras;
|
|
1210
|
-
|
|
1211
|
-
} else {
|
|
1212
|
-
|
|
1213
|
-
console.warn('THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras);
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
/**
|
|
1222
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
|
|
1223
|
-
*
|
|
1224
|
-
* @param {THREE.BufferGeometry} geometry
|
|
1225
|
-
* @param {Array<GLTF.Target>} targets
|
|
1226
|
-
* @param {Array<THREE.BufferAttribute>} accessors
|
|
1227
|
-
*/
|
|
1228
|
-
function addMorphTargets(geometry, targets, accessors) {
|
|
1229
|
-
|
|
1230
|
-
let hasMorphPosition = false;
|
|
1231
|
-
let hasMorphNormal = false;
|
|
1232
|
-
|
|
1233
|
-
let i, il, j, jl;
|
|
1234
|
-
for (i = 0, il = targets.length; i < il; i++) {
|
|
1235
|
-
|
|
1236
|
-
const target = targets[i];
|
|
1237
|
-
|
|
1238
|
-
if (target.POSITION !== undefined) hasMorphPosition = true;
|
|
1239
|
-
if (target.NORMAL !== undefined) hasMorphNormal = true;
|
|
1240
|
-
|
|
1241
|
-
if (hasMorphPosition && hasMorphNormal) break;
|
|
1242
|
-
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
if (!hasMorphPosition && !hasMorphNormal) return;
|
|
1246
|
-
|
|
1247
|
-
const morphPositions = [];
|
|
1248
|
-
const morphNormals = [];
|
|
1249
|
-
|
|
1250
|
-
for (i = 0, il = targets.length; i < il; i++) {
|
|
1251
|
-
|
|
1252
|
-
const target = targets[i];
|
|
1253
|
-
const attributeName = 'morphTarget' + i;
|
|
1254
|
-
|
|
1255
|
-
if (hasMorphPosition) {
|
|
1256
|
-
let positionAttribute;
|
|
1257
|
-
|
|
1258
|
-
// Three.js morph position is absolute value. The formula is
|
|
1259
|
-
// basePosition
|
|
1260
|
-
// + weight0 * ( morphPosition0 - basePosition )
|
|
1261
|
-
// + weight1 * ( morphPosition1 - basePosition )
|
|
1262
|
-
// ...
|
|
1263
|
-
// while the glTF one is relative
|
|
1264
|
-
// basePosition
|
|
1265
|
-
// + weight0 * glTFmorphPosition0
|
|
1266
|
-
// + weight1 * glTFmorphPosition1
|
|
1267
|
-
// ...
|
|
1268
|
-
// then we need to convert from relative to absolute here.
|
|
1269
|
-
|
|
1270
|
-
if (target.POSITION !== undefined) {
|
|
1271
|
-
|
|
1272
|
-
// Cloning not to pollute original accessor
|
|
1273
|
-
positionAttribute = cloneBufferAttribute(accessors[target.POSITION]);
|
|
1274
|
-
positionAttribute.name = attributeName;
|
|
1275
|
-
|
|
1276
|
-
const position = geometry.attributes.position;
|
|
1277
|
-
|
|
1278
|
-
for (j = 0, jl = positionAttribute.count; j < jl; j++) {
|
|
1279
|
-
|
|
1280
|
-
positionAttribute.setXYZ(
|
|
1281
|
-
j,
|
|
1282
|
-
positionAttribute.getX(j) + position.getX(j),
|
|
1283
|
-
positionAttribute.getY(j) + position.getY(j),
|
|
1284
|
-
positionAttribute.getZ(j) + position.getZ(j)
|
|
1285
|
-
);
|
|
1286
|
-
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
} else {
|
|
1290
|
-
|
|
1291
|
-
positionAttribute = geometry.attributes.position;
|
|
1292
|
-
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
morphPositions.push(positionAttribute);
|
|
1296
|
-
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
if (hasMorphNormal) {
|
|
1300
|
-
|
|
1301
|
-
// see target.POSITION's comment
|
|
1302
|
-
|
|
1303
|
-
let normalAttribute;
|
|
1304
|
-
|
|
1305
|
-
if (target.NORMAL !== undefined) {
|
|
1306
|
-
|
|
1307
|
-
normalAttribute = cloneBufferAttribute(accessors[target.NORMAL]);
|
|
1308
|
-
normalAttribute.name = attributeName;
|
|
1309
|
-
|
|
1310
|
-
const normal = geometry.attributes.normal;
|
|
1311
|
-
|
|
1312
|
-
for (j = 0, jl = normalAttribute.count; j < jl; j++) {
|
|
1313
|
-
|
|
1314
|
-
normalAttribute.setXYZ(
|
|
1315
|
-
j,
|
|
1316
|
-
normalAttribute.getX(j) + normal.getX(j),
|
|
1317
|
-
normalAttribute.getY(j) + normal.getY(j),
|
|
1318
|
-
normalAttribute.getZ(j) + normal.getZ(j)
|
|
1319
|
-
);
|
|
1320
|
-
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
} else {
|
|
1324
|
-
|
|
1325
|
-
normalAttribute = geometry.attributes.normal;
|
|
1326
|
-
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
morphNormals.push(normalAttribute);
|
|
1330
|
-
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
if (hasMorphPosition) geometry.morphAttributes.position = morphPositions;
|
|
1336
|
-
if (hasMorphNormal) geometry.morphAttributes.normal = morphNormals;
|
|
1337
|
-
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
/**
|
|
1341
|
-
* @param {THREE.Mesh} mesh
|
|
1342
|
-
* @param {GLTF.Mesh} meshDef
|
|
1343
|
-
*/
|
|
1344
|
-
function updateMorphTargets(mesh, meshDef) {
|
|
1345
|
-
|
|
1346
|
-
mesh.updateMorphTargets();
|
|
1347
|
-
|
|
1348
|
-
let i, il;
|
|
1349
|
-
|
|
1350
|
-
if (meshDef.weights !== undefined) {
|
|
1351
|
-
|
|
1352
|
-
for (i = 0, il = meshDef.weights.length; i < il; i++) {
|
|
1353
|
-
|
|
1354
|
-
mesh.morphTargetInfluences[i] = meshDef.weights[i];
|
|
1355
|
-
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
// .extras has user-defined data, so check that .extras.targetNames is an array.
|
|
1361
|
-
if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
|
|
1362
|
-
|
|
1363
|
-
const targetNames = meshDef.extras.targetNames;
|
|
1364
|
-
|
|
1365
|
-
if (mesh.morphTargetInfluences.length === targetNames.length) {
|
|
1366
|
-
|
|
1367
|
-
mesh.morphTargetDictionary = {};
|
|
1368
|
-
|
|
1369
|
-
for (i = 0, il = targetNames.length; i < il; i++) {
|
|
1370
|
-
|
|
1371
|
-
mesh.morphTargetDictionary[targetNames[i]] = i;
|
|
1372
|
-
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
} else {
|
|
1376
|
-
|
|
1377
|
-
console.warn('THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.');
|
|
1378
|
-
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
function isPrimitiveEqual(a, b) {
|
|
1386
|
-
|
|
1387
|
-
if (a.indices !== b.indices) {
|
|
1388
|
-
|
|
1389
|
-
return false;
|
|
1390
|
-
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
return isObjectEqual(a.attributes, b.attributes);
|
|
1394
|
-
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
function isObjectEqual(a, b) {
|
|
1398
|
-
|
|
1399
|
-
if (Object.keys(a).length !== Object.keys(b).length) return false;
|
|
1400
|
-
|
|
1401
|
-
for (let key in a) {
|
|
1402
|
-
|
|
1403
|
-
if (a[key] !== b[key]) return false;
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
return true;
|
|
1408
|
-
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
function isArrayEqual(a, b) {
|
|
1412
|
-
|
|
1413
|
-
if (a.length !== b.length) return false;
|
|
1414
|
-
|
|
1415
|
-
let i = 0;
|
|
1416
|
-
const il = a.length;
|
|
1417
|
-
for (; i < il; i++) {
|
|
1418
|
-
|
|
1419
|
-
if (a[i] !== b[i]) return false;
|
|
1420
|
-
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
return true;
|
|
1424
|
-
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
function getCachedGeometry(cache, newPrimitive) {
|
|
1428
|
-
|
|
1429
|
-
let i = 0;
|
|
1430
|
-
const il = cache.length;
|
|
1431
|
-
for (; i < il; i++) {
|
|
1432
|
-
|
|
1433
|
-
const cached = cache[i];
|
|
1434
|
-
|
|
1435
|
-
if (isPrimitiveEqual(cached.primitive, newPrimitive)) return cached.promise;
|
|
1436
|
-
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
return null;
|
|
1440
|
-
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
function getCachedCombinedGeometry(cache, geometries) {
|
|
1444
|
-
|
|
1445
|
-
let i = 0;
|
|
1446
|
-
const il = cache.length;
|
|
1447
|
-
for (; i < il; i++) {
|
|
1448
|
-
|
|
1449
|
-
const cached = cache[i];
|
|
1450
|
-
|
|
1451
|
-
if (isArrayEqual(geometries, cached.baseGeometries)) return cached.geometry;
|
|
1452
|
-
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
return null;
|
|
1456
|
-
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
function getCachedMultiPassGeometry(cache, geometry, primitives) {
|
|
1460
|
-
|
|
1461
|
-
let i = 0;
|
|
1462
|
-
const il = cache.length;
|
|
1463
|
-
for (; i < il; i++) {
|
|
1464
|
-
|
|
1465
|
-
const cached = cache[i];
|
|
1466
|
-
|
|
1467
|
-
if (geometry === cached.baseGeometry && isArrayEqual(primitives, cached.primitives)) return cached.geometry;
|
|
1468
|
-
|
|
1469
|
-
}
|
|
1470
|
-
|
|
1471
|
-
return null;
|
|
1472
|
-
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
function cloneBufferAttribute(attribute) {
|
|
1476
|
-
|
|
1477
|
-
if (attribute.isInterleavedBufferAttribute) {
|
|
1478
|
-
|
|
1479
|
-
const count = attribute.count;
|
|
1480
|
-
const itemSize = attribute.itemSize;
|
|
1481
|
-
const array = attribute.array.slice(0, count * itemSize);
|
|
1482
|
-
|
|
1483
|
-
for (let i = 0; i < count; ++i) {
|
|
1484
|
-
|
|
1485
|
-
array[i] = attribute.getX(i);
|
|
1486
|
-
if (itemSize >= 2) array[i + 1] = attribute.getY(i);
|
|
1487
|
-
if (itemSize >= 3) array[i + 2] = attribute.getZ(i);
|
|
1488
|
-
if (itemSize >= 4) array[i + 3] = attribute.getW(i);
|
|
1489
|
-
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
return new THREE.BufferAttribute(array, itemSize, attribute.normalized);
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
return attribute.clone();
|
|
1497
|
-
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
/**
|
|
1501
|
-
* Checks if we can build a single Mesh with MultiMaterial from multiple primitives.
|
|
1502
|
-
* Returns true if all primitives use the same attributes/morphAttributes/mode
|
|
1503
|
-
* and also have index. Otherwise returns false.
|
|
1504
|
-
*
|
|
1505
|
-
* @param {Array<GLTF.Primitive>} primitives
|
|
1506
|
-
* @return {Boolean}
|
|
1507
|
-
*/
|
|
1508
|
-
function isMultiPassGeometry(primitives) {
|
|
1509
|
-
|
|
1510
|
-
if (primitives.length < 2) return false;
|
|
1511
|
-
|
|
1512
|
-
const primitive0 = primitives[0];
|
|
1513
|
-
const targets0 = primitive0.targets || [];
|
|
1514
|
-
|
|
1515
|
-
if (primitive0.indices === undefined) return false;
|
|
1516
|
-
|
|
1517
|
-
let i = 1;
|
|
1518
|
-
const il = primitives.length;
|
|
1519
|
-
for (; i < il; i++) {
|
|
1520
|
-
|
|
1521
|
-
const primitive = primitives[i];
|
|
1522
|
-
|
|
1523
|
-
if (primitive0.mode !== primitive.mode) return false;
|
|
1524
|
-
if (primitive.indices === undefined) return false;
|
|
1525
|
-
if (!isObjectEqual(primitive0.attributes, primitive.attributes)) return false;
|
|
1526
|
-
|
|
1527
|
-
const targets = primitive.targets || [];
|
|
1528
|
-
|
|
1529
|
-
if (targets0.length !== targets.length) return false;
|
|
1530
|
-
|
|
1531
|
-
let j = 0;
|
|
1532
|
-
const jl = targets0.length;
|
|
1533
|
-
for (; j < jl; j++) {
|
|
1534
|
-
|
|
1535
|
-
if (!isObjectEqual(targets0[j], targets[j])) return false;
|
|
1536
|
-
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
return true;
|
|
1542
|
-
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
/* GLTF PARSER */
|
|
1546
|
-
|
|
1547
|
-
function GLTFParser(json, extensions, options) {
|
|
1548
|
-
|
|
1549
|
-
this.json = json || {};
|
|
1550
|
-
this.extensions = extensions || {};
|
|
1551
|
-
this.options = options || {};
|
|
1552
|
-
|
|
1553
|
-
// loader object cache
|
|
1554
|
-
this.cache = new GLTFRegistry();
|
|
1555
|
-
|
|
1556
|
-
// BufferGeometry caching
|
|
1557
|
-
this.primitiveCache = [];
|
|
1558
|
-
this.multiplePrimitivesCache = [];
|
|
1559
|
-
this.multiPassGeometryCache = [];
|
|
1560
|
-
|
|
1561
|
-
this.textureLoader = new THREE.TextureLoader(this.options.manager);
|
|
1562
|
-
this.textureLoader.setCrossOrigin(this.options.crossOrigin);
|
|
1563
|
-
|
|
1564
|
-
this.fileLoader = new THREE.FileLoader(this.options.manager);
|
|
1565
|
-
this.fileLoader.setResponseType('arraybuffer');
|
|
1566
|
-
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
GLTFParser.prototype.parse = function (onLoad, onError) {
|
|
1570
|
-
|
|
1571
|
-
const json = this.json;
|
|
1572
|
-
|
|
1573
|
-
// Clear the loader cache
|
|
1574
|
-
this.cache.removeAll();
|
|
1575
|
-
|
|
1576
|
-
// Mark the special nodes/meshes in json for efficient parse
|
|
1577
|
-
this.markDefs();
|
|
1578
|
-
|
|
1579
|
-
// Fire the callback on complete
|
|
1580
|
-
this.getMultiDependencies([
|
|
1581
|
-
|
|
1582
|
-
'scene',
|
|
1583
|
-
'animation',
|
|
1584
|
-
'camera'
|
|
1585
|
-
|
|
1586
|
-
]).then(function (dependencies) {
|
|
1587
|
-
|
|
1588
|
-
const scenes = dependencies.scenes || [];
|
|
1589
|
-
const scene = scenes[json.scene || 0];
|
|
1590
|
-
const animations = dependencies.animations || [];
|
|
1591
|
-
const cameras = dependencies.cameras || [];
|
|
1592
|
-
|
|
1593
|
-
onLoad(scene, scenes, cameras, animations, json);
|
|
1594
|
-
|
|
1595
|
-
}).catch(onError);
|
|
1596
|
-
|
|
1597
|
-
};
|
|
1598
|
-
|
|
1599
|
-
/**
|
|
1600
|
-
* Marks the special nodes/meshes in json for efficient parse.
|
|
1601
|
-
*/
|
|
1602
|
-
GLTFParser.prototype.markDefs = function () {
|
|
1603
|
-
|
|
1604
|
-
const nodeDefs = this.json.nodes || [];
|
|
1605
|
-
const skinDefs = this.json.skins || [];
|
|
1606
|
-
const meshDefs = this.json.meshes || [];
|
|
1607
|
-
|
|
1608
|
-
const meshReferences = {};
|
|
1609
|
-
const meshUses = {};
|
|
1610
|
-
|
|
1611
|
-
// Nothing in the node definition indicates whether it is a Bone or an
|
|
1612
|
-
// Object3D. Use the skins' joint references to mark bones.
|
|
1613
|
-
let skinIndex = 0;
|
|
1614
|
-
const skinLength = skinDefs.length;
|
|
1615
|
-
for (; skinIndex < skinLength; skinIndex++) {
|
|
1616
|
-
|
|
1617
|
-
const joints = skinDefs[skinIndex].joints;
|
|
1618
|
-
|
|
1619
|
-
let i = 0;
|
|
1620
|
-
const il = joints.length;
|
|
1621
|
-
for (; i < il; i++) {
|
|
1622
|
-
|
|
1623
|
-
nodeDefs[joints[i]].isBone = true;
|
|
1624
|
-
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
// Meshes can (and should) be reused by multiple nodes in a glTF asset. To
|
|
1630
|
-
// avoid having more than one THREE.Mesh with the same name, count
|
|
1631
|
-
// references and rename instances below.
|
|
1632
|
-
//
|
|
1633
|
-
// Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
|
|
1634
|
-
let nodeIndex = 0;
|
|
1635
|
-
const nodeLength = nodeDefs.length;
|
|
1636
|
-
for (; nodeIndex < nodeLength; nodeIndex++) {
|
|
1637
|
-
|
|
1638
|
-
const nodeDef = nodeDefs[nodeIndex];
|
|
1639
|
-
|
|
1640
|
-
if (nodeDef.mesh !== undefined) {
|
|
1641
|
-
|
|
1642
|
-
if (meshReferences[nodeDef.mesh] === undefined) {
|
|
1643
|
-
|
|
1644
|
-
meshReferences[nodeDef.mesh] = meshUses[nodeDef.mesh] = 0;
|
|
1645
|
-
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
meshReferences[nodeDef.mesh]++;
|
|
1649
|
-
|
|
1650
|
-
// Nothing in the mesh definition indicates whether it is
|
|
1651
|
-
// a SkinnedMesh or Mesh. Use the node's mesh reference
|
|
1652
|
-
// to mark SkinnedMesh if node has skin.
|
|
1653
|
-
if (nodeDef.skin !== undefined) {
|
|
1654
|
-
|
|
1655
|
-
meshDefs[nodeDef.mesh].isSkinnedMesh = true;
|
|
1656
|
-
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
this.json.meshReferences = meshReferences;
|
|
1664
|
-
this.json.meshUses = meshUses;
|
|
1665
|
-
|
|
1666
|
-
};
|
|
1667
|
-
|
|
1668
|
-
/**
|
|
1669
|
-
* Requests the specified dependency asynchronously, with caching.
|
|
1670
|
-
* @param {string} type
|
|
1671
|
-
* @param {number} index
|
|
1672
|
-
* @return {Promise<Object>}
|
|
1673
|
-
*/
|
|
1674
|
-
GLTFParser.prototype.getDependency = function (type, index) {
|
|
1675
|
-
|
|
1676
|
-
const cacheKey = type + ':' + index;
|
|
1677
|
-
let dependency = this.cache.get(cacheKey);
|
|
1678
|
-
|
|
1679
|
-
if (!dependency) {
|
|
1680
|
-
|
|
1681
|
-
switch (type) {
|
|
1682
|
-
|
|
1683
|
-
case 'scene':
|
|
1684
|
-
dependency = this.loadScene(index);
|
|
1685
|
-
break;
|
|
1686
|
-
|
|
1687
|
-
case 'node':
|
|
1688
|
-
dependency = this.loadNode(index);
|
|
1689
|
-
break;
|
|
1690
|
-
|
|
1691
|
-
case 'mesh':
|
|
1692
|
-
dependency = this.loadMesh(index);
|
|
1693
|
-
break;
|
|
1694
|
-
|
|
1695
|
-
case 'accessor':
|
|
1696
|
-
dependency = this.loadAccessor(index);
|
|
1697
|
-
break;
|
|
1698
|
-
|
|
1699
|
-
case 'bufferView':
|
|
1700
|
-
dependency = this.loadBufferView(index);
|
|
1701
|
-
break;
|
|
1702
|
-
|
|
1703
|
-
case 'buffer':
|
|
1704
|
-
dependency = this.loadBuffer(index);
|
|
1705
|
-
break;
|
|
1706
|
-
|
|
1707
|
-
case 'material':
|
|
1708
|
-
dependency = this.loadMaterial(index);
|
|
1709
|
-
break;
|
|
1710
|
-
|
|
1711
|
-
case 'texture':
|
|
1712
|
-
dependency = this.loadTexture(index);
|
|
1713
|
-
break;
|
|
1714
|
-
|
|
1715
|
-
case 'skin':
|
|
1716
|
-
dependency = this.loadSkin(index);
|
|
1717
|
-
break;
|
|
1718
|
-
|
|
1719
|
-
case 'animation':
|
|
1720
|
-
dependency = this.loadAnimation(index);
|
|
1721
|
-
break;
|
|
1722
|
-
|
|
1723
|
-
case 'camera':
|
|
1724
|
-
dependency = this.loadCamera(index);
|
|
1725
|
-
break;
|
|
1726
|
-
|
|
1727
|
-
default:
|
|
1728
|
-
throw new Error('Unknown type: ' + type);
|
|
1729
|
-
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
this.cache.add(cacheKey, dependency);
|
|
1733
|
-
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
return dependency;
|
|
1737
|
-
|
|
1738
|
-
};
|
|
1739
|
-
|
|
1740
|
-
/**
|
|
1741
|
-
* Requests all dependencies of the specified type asynchronously, with caching.
|
|
1742
|
-
* @param {string} type
|
|
1743
|
-
* @return {Promise<Array<Object>>}
|
|
1744
|
-
*/
|
|
1745
|
-
GLTFParser.prototype.getDependencies = function (type) {
|
|
1746
|
-
|
|
1747
|
-
let dependencies = this.cache.get(type);
|
|
1748
|
-
|
|
1749
|
-
if (!dependencies) {
|
|
1750
|
-
|
|
1751
|
-
const parser = this;
|
|
1752
|
-
const defs = this.json[type + (type === 'mesh' ? 'es' : 's')] || [];
|
|
1753
|
-
|
|
1754
|
-
dependencies = Promise.all(defs.map(function (def, index) {
|
|
1755
|
-
|
|
1756
|
-
return parser.getDependency(type, index);
|
|
1757
|
-
|
|
1758
|
-
}));
|
|
1759
|
-
|
|
1760
|
-
this.cache.add(type, dependencies);
|
|
1761
|
-
|
|
1762
|
-
}
|
|
1763
|
-
|
|
1764
|
-
return dependencies;
|
|
1765
|
-
|
|
1766
|
-
};
|
|
1767
|
-
|
|
1768
|
-
/**
|
|
1769
|
-
* Requests all multiple dependencies of the specified types asynchronously, with caching.
|
|
1770
|
-
* @param {Array<string>} types
|
|
1771
|
-
* @return {Promise<Object<Array<Object>>>}
|
|
1772
|
-
*/
|
|
1773
|
-
GLTFParser.prototype.getMultiDependencies = function (types) {
|
|
1774
|
-
|
|
1775
|
-
const results = {};
|
|
1776
|
-
const pendings = [];
|
|
1777
|
-
|
|
1778
|
-
let i = 0;
|
|
1779
|
-
const il = types.length;
|
|
1780
|
-
for (; i < il; i++) {
|
|
1781
|
-
|
|
1782
|
-
const type = types[i];
|
|
1783
|
-
let value = this.getDependencies(type);
|
|
1784
|
-
|
|
1785
|
-
value = value.then(function (key, value) {
|
|
1786
|
-
|
|
1787
|
-
results[key] = value;
|
|
1788
|
-
|
|
1789
|
-
}.bind(this, type + (type === 'mesh' ? 'es' : 's')));
|
|
1790
|
-
|
|
1791
|
-
pendings.push(value);
|
|
1792
|
-
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
return Promise.all(pendings).then(function () {
|
|
1796
|
-
|
|
1797
|
-
return results;
|
|
1798
|
-
|
|
1799
|
-
});
|
|
1800
|
-
|
|
1801
|
-
};
|
|
1802
|
-
|
|
1803
|
-
/**
|
|
1804
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1805
|
-
* @param {number} bufferIndex
|
|
1806
|
-
* @return {Promise<ArrayBuffer>}
|
|
1807
|
-
*/
|
|
1808
|
-
GLTFParser.prototype.loadBuffer = function (bufferIndex) {
|
|
1809
|
-
|
|
1810
|
-
const bufferDef = this.json.buffers[bufferIndex];
|
|
1811
|
-
const loader = this.fileLoader;
|
|
1812
|
-
|
|
1813
|
-
if (bufferDef.type && bufferDef.type !== 'arraybuffer') {
|
|
1814
|
-
|
|
1815
|
-
throw new Error('THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.');
|
|
1816
|
-
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
// If present, GLB container is required to be the first buffer.
|
|
1820
|
-
if (bufferDef.uri === undefined && bufferIndex === 0) {
|
|
1821
|
-
|
|
1822
|
-
return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
|
|
1823
|
-
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
const options = this.options;
|
|
1827
|
-
|
|
1828
|
-
return new Promise(function (resolve, reject) {
|
|
1829
|
-
|
|
1830
|
-
loader.load(resolveURL(bufferDef.uri, options.path), resolve, undefined, function () {
|
|
1831
|
-
|
|
1832
|
-
reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
|
|
1833
|
-
|
|
1834
|
-
});
|
|
1835
|
-
|
|
1836
|
-
});
|
|
1837
|
-
|
|
1838
|
-
};
|
|
1839
|
-
|
|
1840
|
-
/**
|
|
1841
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1842
|
-
* @param {number} bufferViewIndex
|
|
1843
|
-
* @return {Promise<ArrayBuffer>}
|
|
1844
|
-
*/
|
|
1845
|
-
GLTFParser.prototype.loadBufferView = function (bufferViewIndex) {
|
|
1846
|
-
|
|
1847
|
-
const bufferViewDef = this.json.bufferViews[bufferViewIndex];
|
|
1848
|
-
|
|
1849
|
-
return this.getDependency('buffer', bufferViewDef.buffer).then(function (buffer) {
|
|
1850
|
-
|
|
1851
|
-
const byteLength = bufferViewDef.byteLength || 0;
|
|
1852
|
-
const byteOffset = bufferViewDef.byteOffset || 0;
|
|
1853
|
-
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
1854
|
-
|
|
1855
|
-
});
|
|
1856
|
-
|
|
1857
|
-
};
|
|
1858
|
-
|
|
1859
|
-
/**
|
|
1860
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
|
|
1861
|
-
* @param {number} accessorIndex
|
|
1862
|
-
* @return {Promise<THREE.BufferAttribute|THREE.InterleavedBufferAttribute>}
|
|
1863
|
-
*/
|
|
1864
|
-
GLTFParser.prototype.loadAccessor = function (accessorIndex) {
|
|
1865
|
-
|
|
1866
|
-
const parser = this;
|
|
1867
|
-
const json = this.json;
|
|
1868
|
-
|
|
1869
|
-
const accessorDef = this.json.accessors[accessorIndex];
|
|
1870
|
-
|
|
1871
|
-
if (accessorDef.bufferView === undefined && accessorDef.sparse === undefined) {
|
|
1872
|
-
|
|
1873
|
-
// Ignore empty accessors, which may be used to declare runtime
|
|
1874
|
-
// information about attributes coming from another source (e.g. Draco
|
|
1875
|
-
// compression extension).
|
|
1876
|
-
return null;
|
|
1877
|
-
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
const pendingBufferViews = [];
|
|
1881
|
-
|
|
1882
|
-
if (accessorDef.bufferView !== undefined) {
|
|
1883
|
-
|
|
1884
|
-
pendingBufferViews.push(this.getDependency('bufferView', accessorDef.bufferView));
|
|
1885
|
-
|
|
1886
|
-
} else {
|
|
1887
|
-
|
|
1888
|
-
pendingBufferViews.push(null);
|
|
1889
|
-
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
if (accessorDef.sparse !== undefined) {
|
|
1893
|
-
|
|
1894
|
-
pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.indices.bufferView));
|
|
1895
|
-
pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.values.bufferView));
|
|
1896
|
-
|
|
1897
|
-
}
|
|
1898
|
-
|
|
1899
|
-
return Promise.all(pendingBufferViews).then(function (bufferViews) {
|
|
1900
|
-
|
|
1901
|
-
const bufferView = bufferViews[0];
|
|
1902
|
-
|
|
1903
|
-
const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
|
|
1904
|
-
const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
1905
|
-
|
|
1906
|
-
// For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
|
|
1907
|
-
const elementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
1908
|
-
const itemBytes = elementBytes * itemSize;
|
|
1909
|
-
const byteOffset = accessorDef.byteOffset || 0;
|
|
1910
|
-
const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[accessorDef.bufferView].byteStride : undefined;
|
|
1911
|
-
const normalized = accessorDef.normalized === true;
|
|
1912
|
-
let array, bufferAttribute;
|
|
1913
|
-
|
|
1914
|
-
// The buffer is not interleaved if the stride is the item size in bytes.
|
|
1915
|
-
if (byteStride && byteStride !== itemBytes) {
|
|
1916
|
-
|
|
1917
|
-
const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType;
|
|
1918
|
-
let ib = parser.cache.get(ibCacheKey);
|
|
1919
|
-
|
|
1920
|
-
if (!ib) {
|
|
1921
|
-
|
|
1922
|
-
// Use the full buffer if it's interleaved.
|
|
1923
|
-
array = new TypedArray(bufferView);
|
|
1924
|
-
|
|
1925
|
-
// Integer parameters to IB/IBA are in array elements, not bytes.
|
|
1926
|
-
ib = new THREE.InterleavedBuffer(array, byteStride / elementBytes);
|
|
1927
|
-
|
|
1928
|
-
parser.cache.add(ibCacheKey, ib);
|
|
1929
|
-
|
|
1930
|
-
}
|
|
1931
|
-
|
|
1932
|
-
bufferAttribute = new THREE.InterleavedBufferAttribute(ib, itemSize, byteOffset / elementBytes, normalized);
|
|
1933
|
-
|
|
1934
|
-
} else {
|
|
1935
|
-
|
|
1936
|
-
if (bufferView === null) {
|
|
1937
|
-
|
|
1938
|
-
array = new TypedArray(accessorDef.count * itemSize);
|
|
1939
|
-
|
|
1940
|
-
} else {
|
|
1941
|
-
|
|
1942
|
-
array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
|
|
1943
|
-
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
bufferAttribute = new THREE.BufferAttribute(array, itemSize, normalized);
|
|
1947
|
-
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
|
-
// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
|
|
1951
|
-
if (accessorDef.sparse !== undefined) {
|
|
1952
|
-
|
|
1953
|
-
const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
|
|
1954
|
-
const TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
|
|
1955
|
-
|
|
1956
|
-
const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
|
|
1957
|
-
const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
|
|
1958
|
-
|
|
1959
|
-
const sparseIndices = new TypedArrayIndices(bufferViews[1], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices);
|
|
1960
|
-
const sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
|
|
1961
|
-
|
|
1962
|
-
if (bufferView !== null) {
|
|
1963
|
-
|
|
1964
|
-
// Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
|
|
1965
|
-
bufferAttribute.setArray(bufferAttribute.array.slice());
|
|
1966
|
-
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
let i = 0;
|
|
1970
|
-
const il = sparseIndices.length;
|
|
1971
|
-
for (; i < il; i++) {
|
|
1972
|
-
|
|
1973
|
-
const index = sparseIndices[i];
|
|
1974
|
-
|
|
1975
|
-
bufferAttribute.setX(index, sparseValues[i * itemSize]);
|
|
1976
|
-
if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
|
|
1977
|
-
if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
|
|
1978
|
-
if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
|
|
1979
|
-
if (itemSize >= 5) throw new Error('THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.');
|
|
1980
|
-
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
}
|
|
1984
|
-
|
|
1985
|
-
return bufferAttribute;
|
|
1986
|
-
|
|
1987
|
-
});
|
|
1988
|
-
|
|
1989
|
-
};
|
|
1990
|
-
|
|
1991
|
-
/**
|
|
1992
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
|
|
1993
|
-
* @param {number} textureIndex
|
|
1994
|
-
* @return {Promise<THREE.Texture>}
|
|
1995
|
-
*/
|
|
1996
|
-
GLTFParser.prototype.loadTexture = function (textureIndex) {
|
|
1997
|
-
|
|
1998
|
-
const parser = this;
|
|
1999
|
-
const json = this.json;
|
|
2000
|
-
const options = this.options;
|
|
2001
|
-
const textureLoader = this.textureLoader;
|
|
2002
|
-
|
|
2003
|
-
const URL = window.URL || window.webkitURL;
|
|
2004
|
-
|
|
2005
|
-
const textureDef = json.textures[textureIndex];
|
|
2006
|
-
|
|
2007
|
-
const textureExtensions = textureDef.extensions || {};
|
|
2008
|
-
|
|
2009
|
-
let source;
|
|
2010
|
-
|
|
2011
|
-
if (textureExtensions[EXTENSIONS.MSFT_TEXTURE_DDS]) {
|
|
2012
|
-
|
|
2013
|
-
source = json.images[textureExtensions[EXTENSIONS.MSFT_TEXTURE_DDS].source];
|
|
2014
|
-
|
|
2015
|
-
} else {
|
|
2016
|
-
|
|
2017
|
-
source = json.images[textureDef.source];
|
|
2018
|
-
|
|
2019
|
-
}
|
|
2020
|
-
|
|
2021
|
-
let sourceURI = source.uri;
|
|
2022
|
-
let isObjectURL = false;
|
|
2023
|
-
|
|
2024
|
-
if (source.bufferView !== undefined) {
|
|
2025
|
-
|
|
2026
|
-
// Load binary image data from bufferView, if provided.
|
|
2027
|
-
|
|
2028
|
-
sourceURI = parser.getDependency('bufferView', source.bufferView).then(function (bufferView) {
|
|
2029
|
-
|
|
2030
|
-
isObjectURL = true;
|
|
2031
|
-
const blob = new Blob([bufferView], { type: source.mimeType });
|
|
2032
|
-
sourceURI = URL.createObjectURL(blob);
|
|
2033
|
-
return sourceURI;
|
|
2034
|
-
|
|
2035
|
-
});
|
|
2036
|
-
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
return Promise.resolve(sourceURI).then(function (sourceURI) {
|
|
2040
|
-
|
|
2041
|
-
// Load Texture resource.
|
|
2042
|
-
|
|
2043
|
-
let loader = THREE.Loader.Handlers.get(sourceURI);
|
|
2044
|
-
|
|
2045
|
-
if (!loader) {
|
|
2046
|
-
|
|
2047
|
-
loader = textureExtensions[EXTENSIONS.MSFT_TEXTURE_DDS]
|
|
2048
|
-
? parser.extensions[EXTENSIONS.MSFT_TEXTURE_DDS].ddsLoader
|
|
2049
|
-
: textureLoader;
|
|
2050
|
-
|
|
2051
|
-
}
|
|
2052
|
-
|
|
2053
|
-
return new Promise(function (resolve, reject) {
|
|
2054
|
-
|
|
2055
|
-
loader.load(resolveURL(sourceURI, options.path), resolve, undefined, reject);
|
|
2056
|
-
|
|
2057
|
-
});
|
|
2058
|
-
|
|
2059
|
-
}).then(function (texture) {
|
|
2060
|
-
|
|
2061
|
-
// Clean up resources and configure Texture.
|
|
2062
|
-
|
|
2063
|
-
if (isObjectURL === true) {
|
|
2064
|
-
|
|
2065
|
-
URL.revokeObjectURL(sourceURI);
|
|
2066
|
-
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
texture.flipY = false;
|
|
2070
|
-
|
|
2071
|
-
if (textureDef.name !== undefined) texture.name = textureDef.name;
|
|
2072
|
-
|
|
2073
|
-
const samplers = json.samplers || {};
|
|
2074
|
-
const sampler = samplers[textureDef.sampler] || {};
|
|
2075
|
-
|
|
2076
|
-
texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || THREE.LinearFilter;
|
|
2077
|
-
texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || THREE.LinearMipMapLinearFilter;
|
|
2078
|
-
texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || THREE.RepeatWrapping;
|
|
2079
|
-
texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || THREE.RepeatWrapping;
|
|
2080
|
-
|
|
2081
|
-
return texture;
|
|
2082
|
-
|
|
2083
|
-
});
|
|
2084
|
-
|
|
2085
|
-
};
|
|
2086
|
-
|
|
2087
|
-
/**
|
|
2088
|
-
* Asynchronously assigns a texture to the given material parameters.
|
|
2089
|
-
* @param {Object} materialParams
|
|
2090
|
-
* @param {string} textureName
|
|
2091
|
-
* @param {number} textureIndex
|
|
2092
|
-
* @return {Promise}
|
|
2093
|
-
*/
|
|
2094
|
-
GLTFParser.prototype.assignTexture = function (materialParams, textureName, textureIndex) {
|
|
2095
|
-
|
|
2096
|
-
return this.getDependency('texture', textureIndex).then(function (texture) {
|
|
2097
|
-
|
|
2098
|
-
materialParams[textureName] = texture;
|
|
2099
|
-
|
|
2100
|
-
});
|
|
2101
|
-
|
|
2102
|
-
};
|
|
2103
|
-
|
|
2104
|
-
/**
|
|
2105
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
|
|
2106
|
-
* @param {number} materialIndex
|
|
2107
|
-
* @return {Promise<THREE.Material>}
|
|
2108
|
-
*/
|
|
2109
|
-
GLTFParser.prototype.loadMaterial = function (materialIndex) {
|
|
2110
|
-
|
|
2111
|
-
const parser = this;
|
|
2112
|
-
const json = this.json;
|
|
2113
|
-
const extensions = this.extensions;
|
|
2114
|
-
const materialDef = json.materials[materialIndex];
|
|
2115
|
-
|
|
2116
|
-
let materialType;
|
|
2117
|
-
const materialParams = {};
|
|
2118
|
-
const materialExtensions = materialDef.extensions || {};
|
|
2119
|
-
|
|
2120
|
-
const pending = [];
|
|
2121
|
-
|
|
2122
|
-
if (materialExtensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]) {
|
|
2123
|
-
|
|
2124
|
-
const sgExtension = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];
|
|
2125
|
-
materialType = sgExtension.getMaterialType(materialDef);
|
|
2126
|
-
pending.push(sgExtension.extendParams(materialParams, materialDef, parser));
|
|
2127
|
-
|
|
2128
|
-
} else if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
|
|
2129
|
-
|
|
2130
|
-
const kmuExtension = extensions[EXTENSIONS.KHR_MATERIALS_UNLIT];
|
|
2131
|
-
materialType = kmuExtension.getMaterialType(materialDef);
|
|
2132
|
-
pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
|
|
2133
|
-
|
|
2134
|
-
} else {
|
|
2135
|
-
|
|
2136
|
-
// Specification:
|
|
2137
|
-
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
|
|
2138
|
-
|
|
2139
|
-
materialType = THREE.MeshStandardMaterial;
|
|
2140
|
-
|
|
2141
|
-
const metallicRoughness = materialDef.pbrMetallicRoughness || {};
|
|
2142
|
-
|
|
2143
|
-
materialParams.color = new THREE.Color(1.0, 1.0, 1.0);
|
|
2144
|
-
materialParams.opacity = 1.0;
|
|
2145
|
-
|
|
2146
|
-
if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
|
2147
|
-
|
|
2148
|
-
const array = metallicRoughness.baseColorFactor;
|
|
2149
|
-
|
|
2150
|
-
materialParams.color.fromArray(array);
|
|
2151
|
-
materialParams.opacity = array[3];
|
|
2152
|
-
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
if (metallicRoughness.baseColorTexture !== undefined) {
|
|
2156
|
-
|
|
2157
|
-
pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture.index));
|
|
2158
|
-
|
|
2159
|
-
}
|
|
2160
|
-
|
|
2161
|
-
materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
|
|
2162
|
-
materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
|
|
2163
|
-
|
|
2164
|
-
if (metallicRoughness.metallicRoughnessTexture !== undefined) {
|
|
2165
|
-
|
|
2166
|
-
const textureIndex = metallicRoughness.metallicRoughnessTexture.index;
|
|
2167
|
-
pending.push(parser.assignTexture(materialParams, 'metalnessMap', textureIndex));
|
|
2168
|
-
pending.push(parser.assignTexture(materialParams, 'roughnessMap', textureIndex));
|
|
2169
|
-
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
if (materialDef.doubleSided === true) {
|
|
2175
|
-
|
|
2176
|
-
materialParams.side = THREE.DoubleSide;
|
|
2177
|
-
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
|
|
2181
|
-
|
|
2182
|
-
if (alphaMode === ALPHA_MODES.BLEND) {
|
|
2183
|
-
|
|
2184
|
-
materialParams.transparent = true;
|
|
2185
|
-
|
|
2186
|
-
} else {
|
|
2187
|
-
|
|
2188
|
-
materialParams.transparent = false;
|
|
2189
|
-
|
|
2190
|
-
if (alphaMode === ALPHA_MODES.MASK) {
|
|
2191
|
-
|
|
2192
|
-
materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
|
|
2193
|
-
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
}
|
|
2197
|
-
|
|
2198
|
-
if (materialDef.normalTexture !== undefined && materialType !== THREE.MeshBasicMaterial) {
|
|
2199
|
-
|
|
2200
|
-
pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture.index));
|
|
2201
|
-
|
|
2202
|
-
materialParams.normalScale = new THREE.Vector2(1, 1);
|
|
2203
|
-
|
|
2204
|
-
if (materialDef.normalTexture.scale !== undefined) {
|
|
2205
|
-
|
|
2206
|
-
materialParams.normalScale.set(materialDef.normalTexture.scale, materialDef.normalTexture.scale);
|
|
2207
|
-
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
}
|
|
2211
|
-
|
|
2212
|
-
if (materialDef.occlusionTexture !== undefined && materialType !== THREE.MeshBasicMaterial) {
|
|
2213
|
-
|
|
2214
|
-
pending.push(parser.assignTexture(materialParams, 'aoMap', materialDef.occlusionTexture.index));
|
|
2215
|
-
|
|
2216
|
-
if (materialDef.occlusionTexture.strength !== undefined) {
|
|
2217
|
-
|
|
2218
|
-
materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
|
|
2219
|
-
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
|
-
if (materialDef.emissiveFactor !== undefined && materialType !== THREE.MeshBasicMaterial) {
|
|
2225
|
-
|
|
2226
|
-
materialParams.emissive = new THREE.Color().fromArray(materialDef.emissiveFactor);
|
|
2227
|
-
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
if (materialDef.emissiveTexture !== undefined && materialType !== THREE.MeshBasicMaterial) {
|
|
2231
|
-
|
|
2232
|
-
pending.push(parser.assignTexture(materialParams, 'emissiveMap', materialDef.emissiveTexture.index));
|
|
2233
|
-
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
return Promise.all(pending).then(function () {
|
|
2237
|
-
|
|
2238
|
-
let material;
|
|
2239
|
-
|
|
2240
|
-
if (materialType === THREE.ShaderMaterial) {
|
|
2241
|
-
|
|
2242
|
-
material = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(materialParams);
|
|
2243
|
-
|
|
2244
|
-
} else {
|
|
2245
|
-
|
|
2246
|
-
material = new materialType(materialParams);
|
|
2247
|
-
|
|
2248
|
-
}
|
|
2249
|
-
|
|
2250
|
-
if (materialDef.name !== undefined) material.name = materialDef.name;
|
|
2251
|
-
|
|
2252
|
-
// Normal map textures use OpenGL conventions:
|
|
2253
|
-
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materialnormaltexture
|
|
2254
|
-
if (material.normalScale) {
|
|
2255
|
-
|
|
2256
|
-
material.normalScale.y = -material.normalScale.y;
|
|
2257
|
-
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
// baseColorTexture, emissiveTexture, and specularGlossinessTexture use sRGB encoding.
|
|
2261
|
-
if (material.map) material.map.encoding = THREE.sRGBEncoding;
|
|
2262
|
-
if (material.emissiveMap) material.emissiveMap.encoding = THREE.sRGBEncoding;
|
|
2263
|
-
if (material.specularMap) material.specularMap.encoding = THREE.sRGBEncoding;
|
|
2264
|
-
|
|
2265
|
-
assignExtrasToUserData(material, materialDef);
|
|
2266
|
-
|
|
2267
|
-
if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
|
|
2268
|
-
|
|
2269
|
-
return material;
|
|
2270
|
-
|
|
2271
|
-
});
|
|
2272
|
-
|
|
2273
|
-
};
|
|
2274
|
-
|
|
2275
|
-
/**
|
|
2276
|
-
* @param {THREE.BufferGeometry} geometry
|
|
2277
|
-
* @param {GLTF.Primitive} primitiveDef
|
|
2278
|
-
* @param {Array<THREE.BufferAttribute>} accessors
|
|
2279
|
-
*/
|
|
2280
|
-
function addPrimitiveAttributes(geometry, primitiveDef, accessors) {
|
|
2281
|
-
|
|
2282
|
-
const attributes = primitiveDef.attributes;
|
|
2283
|
-
|
|
2284
|
-
for (let gltfAttributeName in attributes) {
|
|
2285
|
-
|
|
2286
|
-
let threeAttributeName = ATTRIBUTES[gltfAttributeName];
|
|
2287
|
-
const bufferAttribute = accessors[attributes[gltfAttributeName]];
|
|
2288
|
-
|
|
2289
|
-
// Skip attributes already provided by e.g. Draco extension.
|
|
2290
|
-
if (!threeAttributeName) continue;
|
|
2291
|
-
if (threeAttributeName in geometry.attributes) continue;
|
|
2292
|
-
|
|
2293
|
-
geometry.setAttribute(threeAttributeName, bufferAttribute);
|
|
2294
|
-
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
if (primitiveDef.indices !== undefined && !geometry.index) {
|
|
2298
|
-
|
|
2299
|
-
geometry.setIndex(accessors[primitiveDef.indices]);
|
|
2300
|
-
|
|
2301
|
-
}
|
|
2302
|
-
|
|
2303
|
-
if (primitiveDef.targets !== undefined) {
|
|
2304
|
-
|
|
2305
|
-
addMorphTargets(geometry, primitiveDef.targets, accessors);
|
|
2306
|
-
|
|
2307
|
-
}
|
|
2308
|
-
|
|
2309
|
-
assignExtrasToUserData(geometry, primitiveDef);
|
|
2310
|
-
|
|
2311
|
-
}
|
|
2312
|
-
|
|
2313
|
-
/**
|
|
2314
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
|
2315
|
-
*
|
|
2316
|
-
* Creates BufferGeometries from primitives.
|
|
2317
|
-
* If we can build a single BufferGeometry with .groups from multiple primitives, returns one BufferGeometry.
|
|
2318
|
-
* Otherwise, returns BufferGeometries without .groups as many as primitives.
|
|
2319
|
-
*
|
|
2320
|
-
* @param {Array<Object>} primitives
|
|
2321
|
-
* @return {Promise<Array<THREE.BufferGeometry>>}
|
|
2322
|
-
*/
|
|
2323
|
-
GLTFParser.prototype.loadGeometries = function (primitives) {
|
|
2324
|
-
|
|
2325
|
-
const parser = this;
|
|
2326
|
-
const extensions = this.extensions;
|
|
2327
|
-
const cache = this.primitiveCache;
|
|
2328
|
-
|
|
2329
|
-
const isMultiPass = isMultiPassGeometry(primitives);
|
|
2330
|
-
let originalPrimitives;
|
|
2331
|
-
|
|
2332
|
-
if (isMultiPass) {
|
|
2333
|
-
|
|
2334
|
-
originalPrimitives = primitives; // save original primitives and use later
|
|
2335
|
-
|
|
2336
|
-
// We build a single BufferGeometry with .groups from multiple primitives
|
|
2337
|
-
// because all primitives share the same attributes/morph/mode and have indices.
|
|
2338
|
-
|
|
2339
|
-
primitives = [primitives[0]];
|
|
2340
|
-
|
|
2341
|
-
// Sets .groups and combined indices to a geometry later in this method.
|
|
2342
|
-
|
|
2343
|
-
}
|
|
2344
|
-
|
|
2345
|
-
return this.getDependencies('accessor').then(function (accessors) {
|
|
2346
|
-
|
|
2347
|
-
const pending = [];
|
|
2348
|
-
|
|
2349
|
-
let i, il;
|
|
2350
|
-
for (i = 0, il = primitives.length; i < il; i++) {
|
|
2351
|
-
|
|
2352
|
-
const primitive = primitives[i];
|
|
2353
|
-
|
|
2354
|
-
// See if we've already created this geometry
|
|
2355
|
-
const cached = getCachedGeometry(cache, primitive);
|
|
2356
|
-
|
|
2357
|
-
if (cached) {
|
|
2358
|
-
|
|
2359
|
-
// Use the cached geometry if it exists
|
|
2360
|
-
pending.push(cached);
|
|
2361
|
-
|
|
2362
|
-
} else if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
|
|
2363
|
-
|
|
2364
|
-
// Use DRACO geometry if available
|
|
2365
|
-
const geometryPromise = extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]
|
|
2366
|
-
.decodePrimitive(primitive, parser)
|
|
2367
|
-
.then(function (geometry) {
|
|
2368
|
-
|
|
2369
|
-
addPrimitiveAttributes(geometry, primitive, accessors);
|
|
2370
|
-
|
|
2371
|
-
return geometry;
|
|
2372
|
-
|
|
2373
|
-
});
|
|
2374
|
-
|
|
2375
|
-
cache.push({ primitive: primitive, promise: geometryPromise });
|
|
2376
|
-
|
|
2377
|
-
pending.push(geometryPromise);
|
|
2378
|
-
|
|
2379
|
-
} else {
|
|
2380
|
-
|
|
2381
|
-
// Otherwise create a new geometry
|
|
2382
|
-
const geometry = new THREE.BufferGeometry();
|
|
2383
|
-
|
|
2384
|
-
addPrimitiveAttributes(geometry, primitive, accessors);
|
|
2385
|
-
|
|
2386
|
-
const geometryPromise = Promise.resolve(geometry);
|
|
2387
|
-
|
|
2388
|
-
// Cache this geometry
|
|
2389
|
-
cache.push({ primitive: primitive, promise: geometryPromise });
|
|
2390
|
-
|
|
2391
|
-
pending.push(geometryPromise);
|
|
2392
|
-
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
}
|
|
2396
|
-
|
|
2397
|
-
return Promise.all(pending).then(function (geometries) {
|
|
2398
|
-
|
|
2399
|
-
let i, il;
|
|
2400
|
-
|
|
2401
|
-
if (isMultiPass) {
|
|
2402
|
-
|
|
2403
|
-
const baseGeometry = geometries[0];
|
|
2404
|
-
|
|
2405
|
-
// See if we've already created this combined geometry
|
|
2406
|
-
const cache = parser.multiPassGeometryCache;
|
|
2407
|
-
const cached = getCachedMultiPassGeometry(cache, baseGeometry, originalPrimitives);
|
|
2408
|
-
|
|
2409
|
-
if (cached !== null) return [cached.geometry];
|
|
2410
|
-
|
|
2411
|
-
// Cloning geometry because of index override.
|
|
2412
|
-
// Attributes can be reused so cloning by myself here.
|
|
2413
|
-
const geometry = new THREE.BufferGeometry();
|
|
2414
|
-
|
|
2415
|
-
geometry.name = baseGeometry.name;
|
|
2416
|
-
geometry.userData = baseGeometry.userData;
|
|
2417
|
-
|
|
2418
|
-
let key;
|
|
2419
|
-
for (key in baseGeometry.attributes) geometry.setAttribute(key, baseGeometry.attributes[key]);
|
|
2420
|
-
for (key in baseGeometry.morphAttributes) geometry.morphAttributes[key] = baseGeometry.morphAttributes[key];
|
|
2421
|
-
|
|
2422
|
-
const indices = [];
|
|
2423
|
-
let offset = 0;
|
|
2424
|
-
|
|
2425
|
-
for (i = 0, il = originalPrimitives.length; i < il; i++) {
|
|
2426
|
-
|
|
2427
|
-
const accessor = accessors[originalPrimitives[i].indices];
|
|
2428
|
-
|
|
2429
|
-
let j = 0;
|
|
2430
|
-
const jl = accessor.count;
|
|
2431
|
-
for (; j < jl; j++) indices.push(accessor.array[j]);
|
|
2432
|
-
|
|
2433
|
-
geometry.addGroup(offset, accessor.count, i);
|
|
2434
|
-
|
|
2435
|
-
offset += accessor.count;
|
|
2436
|
-
|
|
2437
|
-
}
|
|
2438
|
-
|
|
2439
|
-
geometry.setIndex(indices);
|
|
2440
|
-
|
|
2441
|
-
cache.push({ geometry: geometry, baseGeometry: baseGeometry, primitives: originalPrimitives });
|
|
2442
|
-
|
|
2443
|
-
return [geometry];
|
|
2444
|
-
|
|
2445
|
-
} else if (geometries.length > 1 && THREE.BufferGeometryUtils !== undefined) {
|
|
2446
|
-
|
|
2447
|
-
// Tries to merge geometries with BufferGeometryUtils if possible
|
|
2448
|
-
|
|
2449
|
-
for (i = 1, il = primitives.length; i < il; i++) {
|
|
2450
|
-
|
|
2451
|
-
// can't merge if draw mode is different
|
|
2452
|
-
if (primitives[0].mode !== primitives[i].mode) return geometries;
|
|
2453
|
-
|
|
2454
|
-
}
|
|
2455
|
-
|
|
2456
|
-
// See if we've already created this combined geometry
|
|
2457
|
-
const cache = parser.multiplePrimitivesCache;
|
|
2458
|
-
const cached = getCachedCombinedGeometry(cache, geometries);
|
|
2459
|
-
|
|
2460
|
-
if (cached) {
|
|
2461
|
-
|
|
2462
|
-
if (cached.geometry !== null) return [cached.geometry];
|
|
2463
|
-
|
|
2464
|
-
} else {
|
|
2465
|
-
|
|
2466
|
-
const geometry = THREE.BufferGeometryUtils.mergeBufferGeometries(geometries, true);
|
|
2467
|
-
|
|
2468
|
-
cache.push({ geometry: geometry, baseGeometries: geometries });
|
|
2469
|
-
|
|
2470
|
-
if (geometry !== null) return [geometry];
|
|
2471
|
-
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
|
-
return geometries;
|
|
2477
|
-
|
|
2478
|
-
});
|
|
2479
|
-
|
|
2480
|
-
});
|
|
2481
|
-
|
|
2482
|
-
};
|
|
2483
|
-
|
|
2484
|
-
/**
|
|
2485
|
-
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
|
|
2486
|
-
* @param {number} meshIndex
|
|
2487
|
-
* @return {Promise<THREE.Group|THREE.Mesh|THREE.SkinnedMesh>}
|
|
2488
|
-
*/
|
|
2489
|
-
GLTFParser.prototype.loadMesh = function (meshIndex) {
|
|
2490
|
-
|
|
2491
|
-
const scope = this;
|
|
2492
|
-
const json = this.json;
|
|
2493
|
-
const extensions = this.extensions;
|
|
2494
|
-
|
|
2495
|
-
const meshDef = json.meshes[meshIndex];
|
|
2496
|
-
|
|
2497
|
-
return this.getMultiDependencies([
|
|
2498
|
-
|
|
2499
|
-
'accessor',
|
|
2500
|
-
'material'
|
|
2501
|
-
|
|
2502
|
-
]).then(function (dependencies) {
|
|
2503
|
-
|
|
2504
|
-
const primitives = meshDef.primitives;
|
|
2505
|
-
const originalMaterials = [];
|
|
2506
|
-
|
|
2507
|
-
for (let i = 0, il = primitives.length; i < il; i++) {
|
|
2508
|
-
|
|
2509
|
-
originalMaterials[i] = primitives[i].material === undefined
|
|
2510
|
-
? createDefaultMaterial()
|
|
2511
|
-
: dependencies.materials[primitives[i].material];
|
|
2512
|
-
|
|
2513
|
-
}
|
|
2514
|
-
|
|
2515
|
-
return scope.loadGeometries(primitives).then(function (geometries) {
|
|
2516
|
-
|
|
2517
|
-
const isMultiMaterial = geometries.length === 1 && geometries[0].groups.length > 0;
|
|
2518
|
-
|
|
2519
|
-
const meshes = [];
|
|
2520
|
-
|
|
2521
|
-
let material;
|
|
2522
|
-
|
|
2523
|
-
for (let i = 0, il = geometries.length; i < il; i++) {
|
|
2524
|
-
|
|
2525
|
-
const geometry = geometries[i];
|
|
2526
|
-
const primitive = primitives[i];
|
|
2527
|
-
|
|
2528
|
-
// 1. create Mesh
|
|
2529
|
-
|
|
2530
|
-
let mesh;
|
|
2531
|
-
|
|
2532
|
-
material = isMultiMaterial ? originalMaterials : originalMaterials[i];
|
|
2533
|
-
|
|
2534
|
-
if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
|
|
2535
|
-
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
|
|
2536
|
-
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
|
|
2537
|
-
primitive.mode === undefined) {
|
|
2538
|
-
|
|
2539
|
-
// .isSkinnedMesh isn't in glTF spec. See .markDefs()
|
|
2540
|
-
mesh = meshDef.isSkinnedMesh === true
|
|
2541
|
-
? new THREE.SkinnedMesh(geometry, material)
|
|
2542
|
-
: new THREE.Mesh(geometry, material);
|
|
2543
|
-
|
|
2544
|
-
if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
|
|
2545
|
-
|
|
2546
|
-
mesh.drawMode = THREE.TriangleStripDrawMode;
|
|
2547
|
-
|
|
2548
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
|
|
2549
|
-
|
|
2550
|
-
mesh.drawMode = THREE.TriangleFanDrawMode;
|
|
2551
|
-
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
|
|
2555
|
-
|
|
2556
|
-
mesh = new THREE.LineSegments(geometry, material);
|
|
2557
|
-
|
|
2558
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
|
|
2559
|
-
|
|
2560
|
-
mesh = new THREE.Line(geometry, material);
|
|
2561
|
-
|
|
2562
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
|
|
2563
|
-
|
|
2564
|
-
mesh = new THREE.LineLoop(geometry, material);
|
|
2565
|
-
|
|
2566
|
-
} else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
|
|
2567
|
-
|
|
2568
|
-
mesh = new THREE.Points(geometry, material);
|
|
2569
|
-
|
|
2570
|
-
} else {
|
|
2571
|
-
|
|
2572
|
-
throw new Error('THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode);
|
|
2573
|
-
|
|
2574
|
-
}
|
|
2575
|
-
|
|
2576
|
-
if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
|
|
2577
|
-
|
|
2578
|
-
updateMorphTargets(mesh, meshDef);
|
|
2579
|
-
|
|
2580
|
-
}
|
|
2581
|
-
|
|
2582
|
-
mesh.name = meshDef.name || ('mesh_' + meshIndex);
|
|
2583
|
-
|
|
2584
|
-
if (geometries.length > 1) mesh.name += '_' + i;
|
|
2585
|
-
|
|
2586
|
-
assignExtrasToUserData(mesh, meshDef);
|
|
2587
|
-
|
|
2588
|
-
meshes.push(mesh);
|
|
2589
|
-
|
|
2590
|
-
// 2. update Material depending on Mesh and BufferGeometry
|
|
2591
|
-
|
|
2592
|
-
const materials = isMultiMaterial ? mesh.material : [mesh.material];
|
|
2593
|
-
|
|
2594
|
-
const useVertexColors = geometry.attributes.color !== undefined;
|
|
2595
|
-
const useFlatShading = geometry.attributes.normal === undefined;
|
|
2596
|
-
const useSkinning = mesh.isSkinnedMesh === true;
|
|
2597
|
-
const useMorphTargets = Object.keys(geometry.morphAttributes).length > 0;
|
|
2598
|
-
const useMorphNormals = useMorphTargets && geometry.morphAttributes.normal !== undefined;
|
|
2599
|
-
|
|
2600
|
-
let j = 0;
|
|
2601
|
-
const jl = materials.length;
|
|
2602
|
-
for (; j < jl; j++) {
|
|
2603
|
-
|
|
2604
|
-
material = materials[j];
|
|
2605
|
-
|
|
2606
|
-
if (mesh.isPoints) {
|
|
2607
|
-
|
|
2608
|
-
const cacheKey = 'PointsMaterial:' + material.uuid;
|
|
2609
|
-
|
|
2610
|
-
let pointsMaterial = scope.cache.get(cacheKey);
|
|
2611
|
-
|
|
2612
|
-
if (!pointsMaterial) {
|
|
2613
|
-
|
|
2614
|
-
pointsMaterial = new THREE.PointsMaterial();
|
|
2615
|
-
THREE.Material.prototype.copy.call(pointsMaterial, material);
|
|
2616
|
-
pointsMaterial.color.copy(material.color);
|
|
2617
|
-
pointsMaterial.map = material.map;
|
|
2618
|
-
pointsMaterial.lights = false; // PointsMaterial doesn't support lights yet
|
|
2619
|
-
|
|
2620
|
-
scope.cache.add(cacheKey, pointsMaterial);
|
|
2621
|
-
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
material = pointsMaterial;
|
|
2625
|
-
|
|
2626
|
-
} else if (mesh.isLine) {
|
|
2627
|
-
|
|
2628
|
-
const cacheKey = 'LineBasicMaterial:' + material.uuid;
|
|
2629
|
-
|
|
2630
|
-
let lineMaterial = scope.cache.get(cacheKey);
|
|
2631
|
-
|
|
2632
|
-
if (!lineMaterial) {
|
|
2633
|
-
|
|
2634
|
-
lineMaterial = new THREE.LineBasicMaterial();
|
|
2635
|
-
THREE.Material.prototype.copy.call(lineMaterial, material);
|
|
2636
|
-
lineMaterial.color.copy(material.color);
|
|
2637
|
-
lineMaterial.lights = false; // LineBasicMaterial doesn't support lights yet
|
|
2638
|
-
|
|
2639
|
-
scope.cache.add(cacheKey, lineMaterial);
|
|
2640
|
-
|
|
2641
|
-
}
|
|
2642
|
-
|
|
2643
|
-
material = lineMaterial;
|
|
2644
|
-
|
|
2645
|
-
}
|
|
2646
|
-
|
|
2647
|
-
// Clone the material if it will be modified
|
|
2648
|
-
if (useVertexColors || useFlatShading || useSkinning || useMorphTargets) {
|
|
2649
|
-
|
|
2650
|
-
let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
|
|
2651
|
-
|
|
2652
|
-
if (material.isGLTFSpecularGlossinessMaterial) cacheKey += 'specular-glossiness:';
|
|
2653
|
-
if (useSkinning) cacheKey += 'skinning:';
|
|
2654
|
-
if (useVertexColors) cacheKey += 'vertex-colors:';
|
|
2655
|
-
if (useFlatShading) cacheKey += 'flat-shading:';
|
|
2656
|
-
if (useMorphTargets) cacheKey += 'morph-targets:';
|
|
2657
|
-
if (useMorphNormals) cacheKey += 'morph-normals:';
|
|
2658
|
-
|
|
2659
|
-
let cachedMaterial = scope.cache.get(cacheKey);
|
|
2660
|
-
|
|
2661
|
-
if (!cachedMaterial) {
|
|
2662
|
-
|
|
2663
|
-
cachedMaterial = material.isGLTFSpecularGlossinessMaterial
|
|
2664
|
-
? extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].cloneMaterial(material)
|
|
2665
|
-
: material.clone();
|
|
2666
|
-
|
|
2667
|
-
if (useSkinning) cachedMaterial.skinning = true;
|
|
2668
|
-
if (useVertexColors) cachedMaterial.vertexColors = THREE.VertexColors;
|
|
2669
|
-
if (useFlatShading) cachedMaterial.flatShading = true;
|
|
2670
|
-
if (useMorphTargets) cachedMaterial.morphTargets = true;
|
|
2671
|
-
if (useMorphNormals) cachedMaterial.morphNormals = true;
|
|
2672
|
-
|
|
2673
|
-
scope.cache.add(cacheKey, cachedMaterial);
|
|
2674
|
-
|
|
2675
|
-
}
|
|
2676
|
-
|
|
2677
|
-
material = cachedMaterial;
|
|
2678
|
-
|
|
2679
|
-
}
|
|
2680
|
-
|
|
2681
|
-
materials[j] = material;
|
|
2682
|
-
|
|
2683
|
-
// workarounds for mesh and geometry
|
|
2684
|
-
|
|
2685
|
-
if (material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined) {
|
|
2686
|
-
|
|
2687
|
-
console.log('THREE.GLTFLoader: Duplicating UVs to support aoMap.');
|
|
2688
|
-
geometry.setAttribute('uv2', new THREE.BufferAttribute(geometry.attributes.uv.array, 2));
|
|
2689
|
-
|
|
2690
|
-
}
|
|
2691
|
-
|
|
2692
|
-
if (material.isGLTFSpecularGlossinessMaterial) {
|
|
2693
|
-
|
|
2694
|
-
// for GLTFSpecularGlossinessMaterial(ShaderMaterial) uniforms runtime update
|
|
2695
|
-
mesh.onBeforeRender = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].refreshUniforms;
|
|
2696
|
-
|
|
2697
|
-
}
|
|
2698
|
-
|
|
2699
|
-
}
|
|
2700
|
-
|
|
2701
|
-
mesh.material = isMultiMaterial ? materials : materials[0];
|
|
2702
|
-
|
|
2703
|
-
}
|
|
2704
|
-
|
|
2705
|
-
if (meshes.length === 1) {
|
|
2706
|
-
|
|
2707
|
-
return meshes[0];
|
|
2708
|
-
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2711
|
-
const group = new THREE.Group();
|
|
2712
|
-
|
|
2713
|
-
for (let i = 0, il = meshes.length; i < il; i++) {
|
|
2714
|
-
|
|
2715
|
-
group.add(meshes[i]);
|
|
2716
|
-
|
|
2717
|
-
}
|
|
2718
|
-
|
|
2719
|
-
return group;
|
|
2720
|
-
|
|
2721
|
-
});
|
|
2722
|
-
|
|
2723
|
-
});
|
|
2724
|
-
|
|
2725
|
-
};
|
|
2726
|
-
|
|
2727
|
-
/**
|
|
2728
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
|
|
2729
|
-
* @param {number} cameraIndex
|
|
2730
|
-
* @return {Promise<THREE.Camera>}
|
|
2731
|
-
*/
|
|
2732
|
-
GLTFParser.prototype.loadCamera = function (cameraIndex) {
|
|
2733
|
-
|
|
2734
|
-
let camera;
|
|
2735
|
-
const cameraDef = this.json.cameras[cameraIndex];
|
|
2736
|
-
let params = cameraDef[cameraDef.type];
|
|
2737
|
-
|
|
2738
|
-
if (!params) {
|
|
2739
|
-
|
|
2740
|
-
console.warn('THREE.GLTFLoader: Missing camera parameters.');
|
|
2741
|
-
return Promise.reject('THREE.GLTFLoader: Missing camera parameters.');
|
|
2742
|
-
|
|
2743
|
-
}
|
|
2744
|
-
|
|
2745
|
-
if (cameraDef.type === 'perspective') {
|
|
2746
|
-
|
|
2747
|
-
camera = new THREE.PerspectiveCamera(THREE.Math.radToDeg(params.yfov), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6);
|
|
2748
|
-
|
|
2749
|
-
} else if (cameraDef.type === 'orthographic') {
|
|
2750
|
-
|
|
2751
|
-
camera = new THREE.OrthographicCamera(params.xmag / -2, params.xmag / 2, params.ymag / 2, params.ymag / -2, params.znear, params.zfar);
|
|
2752
|
-
|
|
2753
|
-
}
|
|
2754
|
-
|
|
2755
|
-
if (cameraDef.name !== undefined) camera.name = cameraDef.name;
|
|
2756
|
-
|
|
2757
|
-
assignExtrasToUserData(camera, cameraDef);
|
|
2758
|
-
|
|
2759
|
-
return Promise.resolve(camera);
|
|
2760
|
-
|
|
2761
|
-
};
|
|
2762
|
-
|
|
2763
|
-
/**
|
|
2764
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
|
|
2765
|
-
* @param {number} skinIndex
|
|
2766
|
-
* @return {Promise<Object>}
|
|
2767
|
-
*/
|
|
2768
|
-
GLTFParser.prototype.loadSkin = function (skinIndex) {
|
|
2769
|
-
|
|
2770
|
-
const skinDef = this.json.skins[skinIndex];
|
|
2771
|
-
|
|
2772
|
-
const skinEntry = { joints: skinDef.joints };
|
|
2773
|
-
|
|
2774
|
-
if (skinDef.inverseBindMatrices === undefined) {
|
|
2775
|
-
|
|
2776
|
-
return Promise.resolve(skinEntry);
|
|
2777
|
-
|
|
2778
|
-
}
|
|
2779
|
-
|
|
2780
|
-
return this.getDependency('accessor', skinDef.inverseBindMatrices).then(function (accessor) {
|
|
2781
|
-
|
|
2782
|
-
skinEntry.inverseBindMatrices = accessor;
|
|
2783
|
-
|
|
2784
|
-
return skinEntry;
|
|
2785
|
-
|
|
2786
|
-
});
|
|
2787
|
-
|
|
2788
|
-
};
|
|
2789
|
-
|
|
2790
|
-
/**
|
|
2791
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
|
|
2792
|
-
* @param {number} animationIndex
|
|
2793
|
-
* @return {Promise<THREE.AnimationClip>}
|
|
2794
|
-
*/
|
|
2795
|
-
GLTFParser.prototype.loadAnimation = function (animationIndex) {
|
|
2796
|
-
|
|
2797
|
-
const json = this.json;
|
|
2798
|
-
|
|
2799
|
-
const animationDef = json.animations[animationIndex];
|
|
2800
|
-
|
|
2801
|
-
return this.getMultiDependencies([
|
|
2802
|
-
|
|
2803
|
-
'accessor',
|
|
2804
|
-
'node'
|
|
2805
|
-
|
|
2806
|
-
]).then(function (dependencies) {
|
|
2807
|
-
|
|
2808
|
-
const tracks = [];
|
|
2809
|
-
|
|
2810
|
-
let i = 0;
|
|
2811
|
-
const il = animationDef.channels.length;
|
|
2812
|
-
for (; i < il; i++) {
|
|
2813
|
-
|
|
2814
|
-
const channel = animationDef.channels[i];
|
|
2815
|
-
const sampler = animationDef.samplers[channel.sampler];
|
|
2816
|
-
|
|
2817
|
-
if (sampler) {
|
|
2818
|
-
|
|
2819
|
-
const target = channel.target;
|
|
2820
|
-
const name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
|
|
2821
|
-
const input = animationDef.parameters !== undefined ? animationDef.parameters[sampler.input] : sampler.input;
|
|
2822
|
-
const output = animationDef.parameters !== undefined ? animationDef.parameters[sampler.output] : sampler.output;
|
|
2823
|
-
|
|
2824
|
-
const inputAccessor = dependencies.accessors[input];
|
|
2825
|
-
const outputAccessor = dependencies.accessors[output];
|
|
2826
|
-
|
|
2827
|
-
const node = dependencies.nodes[name];
|
|
2828
|
-
|
|
2829
|
-
if (node) {
|
|
2830
|
-
|
|
2831
|
-
node.updateMatrix();
|
|
2832
|
-
node.matrixAutoUpdate = true;
|
|
2833
|
-
|
|
2834
|
-
let TypedKeyframeTrack;
|
|
2835
|
-
|
|
2836
|
-
switch (PATH_PROPERTIES[target.path]) {
|
|
2837
|
-
|
|
2838
|
-
case PATH_PROPERTIES.weights:
|
|
2839
|
-
|
|
2840
|
-
TypedKeyframeTrack = THREE.NumberKeyframeTrack;
|
|
2841
|
-
break;
|
|
2842
|
-
|
|
2843
|
-
case PATH_PROPERTIES.rotation:
|
|
2844
|
-
|
|
2845
|
-
TypedKeyframeTrack = THREE.QuaternionKeyframeTrack;
|
|
2846
|
-
break;
|
|
2847
|
-
|
|
2848
|
-
case PATH_PROPERTIES.position:
|
|
2849
|
-
case PATH_PROPERTIES.scale:
|
|
2850
|
-
default:
|
|
2851
|
-
|
|
2852
|
-
TypedKeyframeTrack = THREE.VectorKeyframeTrack;
|
|
2853
|
-
break;
|
|
2854
|
-
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
const targetName = node.name ? node.name : node.uuid;
|
|
2858
|
-
|
|
2859
|
-
const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[sampler.interpolation] : THREE.InterpolateLinear;
|
|
2860
|
-
|
|
2861
|
-
const targetNames = [];
|
|
2862
|
-
|
|
2863
|
-
if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
|
|
2864
|
-
|
|
2865
|
-
// node can be THREE.Group here but
|
|
2866
|
-
// PATH_PROPERTIES.weights(morphTargetInfluences) should be
|
|
2867
|
-
// the property of a mesh object under group.
|
|
2868
|
-
|
|
2869
|
-
node.traverse(function (object) {
|
|
2870
|
-
|
|
2871
|
-
if (object.isMesh === true && object.morphTargetInfluences) {
|
|
2872
|
-
|
|
2873
|
-
targetNames.push(object.name ? object.name : object.uuid);
|
|
2874
|
-
|
|
2875
|
-
}
|
|
2876
|
-
|
|
2877
|
-
});
|
|
2878
|
-
|
|
2879
|
-
} else {
|
|
2880
|
-
|
|
2881
|
-
targetNames.push(targetName);
|
|
2882
|
-
|
|
2883
|
-
}
|
|
2884
|
-
|
|
2885
|
-
// KeyframeTrack.optimize() will modify given 'times' and 'values'
|
|
2886
|
-
// buffers before creating a truncated copy to keep. Because buffers may
|
|
2887
|
-
// be reused by other tracks, make copies here.
|
|
2888
|
-
let j = 0;
|
|
2889
|
-
const jl = targetNames.length;
|
|
2890
|
-
for (; j < jl; j++) {
|
|
2891
|
-
|
|
2892
|
-
const track = new TypedKeyframeTrack(
|
|
2893
|
-
targetNames[j] + '.' + PATH_PROPERTIES[target.path],
|
|
2894
|
-
THREE.AnimationUtils.arraySlice(inputAccessor.array, 0),
|
|
2895
|
-
THREE.AnimationUtils.arraySlice(outputAccessor.array, 0),
|
|
2896
|
-
interpolation
|
|
2897
|
-
);
|
|
2898
|
-
|
|
2899
|
-
// Here is the trick to enable custom interpolation.
|
|
2900
|
-
// Overrides .createInterpolant in a factory method which creates custom interpolation.
|
|
2901
|
-
if (sampler.interpolation === 'CUBICSPLINE') {
|
|
2902
|
-
|
|
2903
|
-
track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
|
|
2904
|
-
|
|
2905
|
-
// A CUBICSPLINE keyframe in glTF has three output values for each input value,
|
|
2906
|
-
// representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
|
|
2907
|
-
// must be divided by three to get the interpolant's sampleSize argument.
|
|
2908
|
-
|
|
2909
|
-
return new GLTFCubicSplineInterpolant(this.times, this.values, this.getValueSize() / 3, result);
|
|
2910
|
-
|
|
2911
|
-
};
|
|
2912
|
-
|
|
2913
|
-
// Workaround, provide an alternate way to know if the interpolant type is cubis spline to track.
|
|
2914
|
-
// track.getInterpolation() doesn't return valid value for custom interpolant.
|
|
2915
|
-
track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
|
|
2916
|
-
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
|
-
tracks.push(track);
|
|
2920
|
-
|
|
2921
|
-
}
|
|
2922
|
-
|
|
2923
|
-
}
|
|
2924
|
-
|
|
2925
|
-
}
|
|
2926
|
-
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
const name = animationDef.name !== undefined ? animationDef.name : 'animation_' + animationIndex;
|
|
2930
|
-
|
|
2931
|
-
return new THREE.AnimationClip(name, undefined, tracks);
|
|
2932
|
-
|
|
2933
|
-
});
|
|
2934
|
-
|
|
2935
|
-
};
|
|
2936
|
-
|
|
2937
|
-
/**
|
|
2938
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
|
|
2939
|
-
* @param {number} nodeIndex
|
|
2940
|
-
* @return {Promise<THREE.Object3D>}
|
|
2941
|
-
*/
|
|
2942
|
-
GLTFParser.prototype.loadNode = function (nodeIndex) {
|
|
2943
|
-
|
|
2944
|
-
const json = this.json;
|
|
2945
|
-
const extensions = this.extensions;
|
|
2946
|
-
|
|
2947
|
-
const meshReferences = json.meshReferences;
|
|
2948
|
-
const meshUses = json.meshUses;
|
|
2949
|
-
|
|
2950
|
-
const nodeDef = json.nodes[nodeIndex];
|
|
2951
|
-
|
|
2952
|
-
return this.getMultiDependencies([
|
|
2953
|
-
|
|
2954
|
-
'mesh',
|
|
2955
|
-
'skin',
|
|
2956
|
-
'camera',
|
|
2957
|
-
'light'
|
|
2958
|
-
|
|
2959
|
-
]).then(function (dependencies) {
|
|
2960
|
-
|
|
2961
|
-
let node;
|
|
2962
|
-
|
|
2963
|
-
// .isBone isn't in glTF spec. See .markDefs
|
|
2964
|
-
if (nodeDef.isBone === true) {
|
|
2965
|
-
|
|
2966
|
-
node = new THREE.Bone();
|
|
2967
|
-
|
|
2968
|
-
} else if (nodeDef.mesh !== undefined) {
|
|
2969
|
-
|
|
2970
|
-
const mesh = dependencies.meshes[nodeDef.mesh];
|
|
2971
|
-
|
|
2972
|
-
if (meshReferences[nodeDef.mesh] > 1) {
|
|
2973
|
-
|
|
2974
|
-
const instanceNum = meshUses[nodeDef.mesh]++;
|
|
2975
|
-
|
|
2976
|
-
node = mesh.clone();
|
|
2977
|
-
node.name += '_instance_' + instanceNum;
|
|
2978
|
-
|
|
2979
|
-
// onBeforeRender copy for Specular-Glossiness
|
|
2980
|
-
node.onBeforeRender = mesh.onBeforeRender;
|
|
2981
|
-
|
|
2982
|
-
let i = 0;
|
|
2983
|
-
const il = node.children.length;
|
|
2984
|
-
for (; i < il; i++) {
|
|
2985
|
-
|
|
2986
|
-
node.children[i].name += '_instance_' + instanceNum;
|
|
2987
|
-
node.children[i].onBeforeRender = mesh.children[i].onBeforeRender;
|
|
2988
|
-
|
|
2989
|
-
}
|
|
2990
|
-
|
|
2991
|
-
} else {
|
|
2992
|
-
|
|
2993
|
-
node = mesh;
|
|
2994
|
-
|
|
2995
|
-
}
|
|
2996
|
-
|
|
2997
|
-
} else if (nodeDef.camera !== undefined) {
|
|
2998
|
-
|
|
2999
|
-
node = dependencies.cameras[nodeDef.camera];
|
|
3000
|
-
|
|
3001
|
-
} else if (nodeDef.extensions
|
|
3002
|
-
&& nodeDef.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
|
|
3003
|
-
&& nodeDef.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL].light !== undefined) {
|
|
3004
|
-
|
|
3005
|
-
const lights = extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL].lights;
|
|
3006
|
-
node = lights[nodeDef.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL].light];
|
|
3007
|
-
|
|
3008
|
-
} else {
|
|
3009
|
-
|
|
3010
|
-
node = new THREE.Object3D();
|
|
3011
|
-
|
|
3012
|
-
}
|
|
3013
|
-
|
|
3014
|
-
if (nodeDef.name !== undefined) {
|
|
3015
|
-
|
|
3016
|
-
node.name = THREE.PropertyBinding.sanitizeNodeName(nodeDef.name);
|
|
3017
|
-
|
|
3018
|
-
}
|
|
3019
|
-
|
|
3020
|
-
assignExtrasToUserData(node, nodeDef);
|
|
3021
|
-
|
|
3022
|
-
if (nodeDef.extensions) addUnknownExtensionsToUserData(extensions, node, nodeDef);
|
|
3023
|
-
|
|
3024
|
-
if (nodeDef.matrix !== undefined) {
|
|
3025
|
-
|
|
3026
|
-
const matrix = new THREE.Matrix4();
|
|
3027
|
-
matrix.fromArray(nodeDef.matrix);
|
|
3028
|
-
node.applyMatrix4(matrix);
|
|
3029
|
-
|
|
3030
|
-
} else {
|
|
3031
|
-
|
|
3032
|
-
if (nodeDef.translation !== undefined) {
|
|
3033
|
-
|
|
3034
|
-
node.position.fromArray(nodeDef.translation);
|
|
3035
|
-
|
|
3036
|
-
}
|
|
3037
|
-
|
|
3038
|
-
if (nodeDef.rotation !== undefined) {
|
|
3039
|
-
|
|
3040
|
-
node.quaternion.fromArray(nodeDef.rotation);
|
|
3041
|
-
|
|
3042
|
-
}
|
|
3043
|
-
|
|
3044
|
-
if (nodeDef.scale !== undefined) {
|
|
3045
|
-
|
|
3046
|
-
node.scale.fromArray(nodeDef.scale);
|
|
3047
|
-
|
|
3048
|
-
}
|
|
3049
|
-
|
|
3050
|
-
}
|
|
3051
|
-
|
|
3052
|
-
return node;
|
|
3053
|
-
|
|
3054
|
-
});
|
|
3055
|
-
|
|
3056
|
-
};
|
|
3057
|
-
|
|
3058
|
-
/**
|
|
3059
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
|
|
3060
|
-
* @param {number} sceneIndex
|
|
3061
|
-
* @return {Promise<THREE.Scene>}
|
|
3062
|
-
*/
|
|
3063
|
-
GLTFParser.prototype.loadScene = function () {
|
|
3064
|
-
|
|
3065
|
-
// scene node hierachy builder
|
|
3066
|
-
|
|
3067
|
-
function buildNodeHierachy(nodeId, parentObject, json, allNodes, skins) {
|
|
3068
|
-
|
|
3069
|
-
const node = allNodes[nodeId];
|
|
3070
|
-
const nodeDef = json.nodes[nodeId];
|
|
3071
|
-
|
|
3072
|
-
// build skeleton here as well
|
|
3073
|
-
|
|
3074
|
-
if (nodeDef.skin !== undefined) {
|
|
3075
|
-
|
|
3076
|
-
const meshes = node.isGroup === true ? node.children : [node];
|
|
3077
|
-
|
|
3078
|
-
for (let i = 0, il = meshes.length; i < il; i++) {
|
|
3079
|
-
|
|
3080
|
-
const mesh = meshes[i];
|
|
3081
|
-
const skinEntry = skins[nodeDef.skin];
|
|
3082
|
-
|
|
3083
|
-
const bones = [];
|
|
3084
|
-
const boneInverses = [];
|
|
3085
|
-
|
|
3086
|
-
let j = 0;
|
|
3087
|
-
const jl = skinEntry.joints.length;
|
|
3088
|
-
for (; j < jl; j++) {
|
|
3089
|
-
|
|
3090
|
-
const jointId = skinEntry.joints[j];
|
|
3091
|
-
const jointNode = allNodes[jointId];
|
|
3092
|
-
|
|
3093
|
-
if (jointNode) {
|
|
3094
|
-
|
|
3095
|
-
bones.push(jointNode);
|
|
3096
|
-
|
|
3097
|
-
const mat = new THREE.Matrix4();
|
|
3098
|
-
|
|
3099
|
-
if (skinEntry.inverseBindMatrices !== undefined) {
|
|
3100
|
-
|
|
3101
|
-
mat.fromArray(skinEntry.inverseBindMatrices.array, j * 16);
|
|
3102
|
-
|
|
3103
|
-
}
|
|
3104
|
-
|
|
3105
|
-
boneInverses.push(mat);
|
|
3106
|
-
|
|
3107
|
-
} else {
|
|
3108
|
-
|
|
3109
|
-
console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', jointId);
|
|
3110
|
-
|
|
3111
|
-
}
|
|
3112
|
-
|
|
3113
|
-
}
|
|
3114
|
-
|
|
3115
|
-
mesh.bind(new THREE.Skeleton(bones, boneInverses), mesh.matrixWorld);
|
|
3116
|
-
|
|
3117
|
-
}
|
|
3118
|
-
|
|
3119
|
-
}
|
|
3120
|
-
|
|
3121
|
-
// build node hierachy
|
|
3122
|
-
|
|
3123
|
-
parentObject.add(node);
|
|
3124
|
-
|
|
3125
|
-
if (nodeDef.children) {
|
|
3126
|
-
|
|
3127
|
-
const children = nodeDef.children;
|
|
3128
|
-
|
|
3129
|
-
for (let i = 0, il = children.length; i < il; i++) {
|
|
3130
|
-
|
|
3131
|
-
const child = children[i];
|
|
3132
|
-
buildNodeHierachy(child, node, json, allNodes, skins);
|
|
3133
|
-
|
|
3134
|
-
}
|
|
3135
|
-
|
|
3136
|
-
}
|
|
3137
|
-
|
|
3138
|
-
}
|
|
3139
|
-
|
|
3140
|
-
return function loadScene(sceneIndex) {
|
|
3141
|
-
|
|
3142
|
-
const json = this.json;
|
|
3143
|
-
const extensions = this.extensions;
|
|
3144
|
-
const sceneDef = this.json.scenes[sceneIndex];
|
|
3145
|
-
|
|
3146
|
-
return this.getMultiDependencies([
|
|
3147
|
-
|
|
3148
|
-
'node',
|
|
3149
|
-
'skin'
|
|
3150
|
-
|
|
3151
|
-
]).then(function (dependencies) {
|
|
3152
|
-
|
|
3153
|
-
const scene = new THREE.Scene();
|
|
3154
|
-
if (sceneDef.name !== undefined) scene.name = sceneDef.name;
|
|
3155
|
-
|
|
3156
|
-
assignExtrasToUserData(scene, sceneDef);
|
|
3157
|
-
|
|
3158
|
-
if (sceneDef.extensions) addUnknownExtensionsToUserData(extensions, scene, sceneDef);
|
|
3159
|
-
|
|
3160
|
-
const nodeIds = sceneDef.nodes || [];
|
|
3161
|
-
|
|
3162
|
-
let i = 0;
|
|
3163
|
-
const il = nodeIds.length;
|
|
3164
|
-
for (; i < il; i++) {
|
|
3165
|
-
|
|
3166
|
-
buildNodeHierachy(nodeIds[i], scene, json, dependencies.nodes, dependencies.skins);
|
|
3167
|
-
|
|
3168
|
-
}
|
|
3169
|
-
|
|
3170
|
-
return scene;
|
|
3171
|
-
|
|
3172
|
-
});
|
|
3173
|
-
|
|
3174
|
-
};
|
|
3175
|
-
|
|
3176
|
-
}();
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
export default GLTFLoader;
|