Skip to content

Commit

Permalink
InstancedMesh: Add support for morph targets. (#817)
Browse files Browse the repository at this point in the history
* Add setMorphAt

* Update three.js

* Add examples

* Update

* Delete examples

* Update patch
  • Loading branch information
Methuselah96 authored Feb 17, 2024
1 parent 1cb1cfb commit 9b8afb8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
41 changes: 39 additions & 2 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,7 @@ index d248a0d..16a111b 100644
//

diff --git a/examples-testing/examples/webgl_camera.ts b/examples-testing/examples/webgl_camera.ts
index a1d44b9..09152d6 100644
index d78fbec..6b84a2c 100644
--- a/examples-testing/examples/webgl_camera.ts
+++ b/examples-testing/examples/webgl_camera.ts
@@ -6,11 +6,11 @@ let SCREEN_WIDTH = window.innerWidth;
Expand All @@ -3076,7 +3076,7 @@ index a1d44b9..09152d6 100644
const frustumSize = 600;

init();
@@ -123,7 +123,7 @@ function init() {
@@ -122,7 +122,7 @@ function init() {

//

Expand Down Expand Up @@ -5500,6 +5500,43 @@ index 8c94528..b0e453e 100644
const amount = parseInt(window.location.search.slice(1)) || 10;
const count = Math.pow(amount, 3);
const dummy = new THREE.Object3D();
diff --git a/examples-testing/examples/webgl_instancing_morph.ts b/examples-testing/examples/webgl_instancing_morph.ts
index 7a4245c..6eecf7c 100644
--- a/examples-testing/examples/webgl_instancing_morph.ts
+++ b/examples-testing/examples/webgl_instancing_morph.ts
@@ -4,7 +4,13 @@ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

import Stats from 'three/addons/libs/stats.module.js';

-let camera, scene, renderer, stats, mesh, mixer, dummy;
+let camera: THREE.PerspectiveCamera,
+ scene: THREE.Scene,
+ renderer: THREE.WebGLRenderer,
+ stats: Stats,
+ mesh: THREE.InstancedMesh,
+ mixer: THREE.AnimationMixer,
+ dummy: THREE.Mesh;

const offset = 5000;

@@ -64,7 +70,7 @@ function init() {
const loader = new GLTFLoader();

loader.load('models/gltf/Horse.glb', function (glb) {
- dummy = glb.scene.children[0];
+ dummy = glb.scene.children[0] as THREE.Mesh;

mesh = new THREE.InstancedMesh(dummy.geometry, dummy.material, 1024);

@@ -142,7 +148,7 @@ function render() {
mesh.setMorphAt(i, dummy);
}

- mesh.morphTexture.needsUpdate = true;
+ mesh.morphTexture!.needsUpdate = true;
}

renderer.render(scene, camera);
diff --git a/examples-testing/examples/webgl_instancing_performance.ts b/examples-testing/examples/webgl_instancing_performance.ts
index 62ed935..b34abd6 100644
--- a/examples-testing/examples/webgl_instancing_performance.ts
Expand Down
1 change: 1 addition & 0 deletions examples-testing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const files = {
'webgl_geometry_text_shapes',
'webgl_geometry_text_stroke',
'webgl_helpers',
'webgl_instancing_morph',
'webgl_instancing_dynamic',
'webgl_instancing_performance',
'webgl_instancing_raycast',
Expand Down
2 changes: 1 addition & 1 deletion three.js
Submodule three.js updated 75 files
+3 −3 .github/workflows/codeql-code-scanning.yml
+1 −1 .github/workflows/report-size.yml
+3 −3 docs/examples/en/loaders/GLTFLoader.html
+2 −3 docs/examples/zh/animations/CCDIKSolver.html
+2 −3 docs/examples/zh/animations/MMDAnimationHelper.html
+2 −3 docs/examples/zh/animations/MMDPhysics.html
+2 −3 docs/examples/zh/controls/ArcballControls.html
+2 −3 docs/examples/zh/controls/MapControls.html
+2 −3 docs/examples/zh/exporters/DRACOExporter.html
+2 −3 docs/examples/zh/exporters/EXRExporter.html
+2 −3 docs/examples/zh/exporters/GLTFExporter.html
+2 −3 docs/examples/zh/exporters/OBJExporter.html
+2 −3 docs/examples/zh/exporters/PLYExporter.html
+2 −3 docs/examples/zh/exporters/STLExporter.html
+2 −3 docs/examples/zh/geometries/SDFGeometryGenerator.html
+2 −3 docs/examples/zh/helpers/VertexTangentsHelper.html
+2 −3 docs/examples/zh/loaders/3DMLoader.html
+4 −14 docs/examples/zh/loaders/GLTFLoader.html
+2 −3 docs/examples/zh/loaders/KTX2Loader.html
+2 −3 docs/examples/zh/loaders/LDrawLoader.html
+2 −3 docs/examples/zh/loaders/PDBLoader.html
+2 −3 docs/examples/zh/math/MeshSurfaceSampler.html
+2 −3 docs/examples/zh/math/convexhull/ConvexHull.html
+2 −3 docs/examples/zh/math/convexhull/Face.html
+2 −3 docs/examples/zh/math/convexhull/HalfEdge.html
+2 −3 docs/examples/zh/math/convexhull/VertexList.html
+2 −3 docs/examples/zh/math/convexhull/VertexNode.html
+2 −3 docs/examples/zh/utils/CameraUtils.html
+2 −3 docs/examples/zh/webxr/XREstimatedLight.html
+1 −0 examples/files.json
+32 −14 examples/jsm/libs/tween.module.js
+1 −0 examples/jsm/nodes/Nodes.js
+7 −0 examples/jsm/nodes/accessors/StorageBufferNode.js
+11 −3 examples/jsm/nodes/core/Node.js
+1 −9 examples/jsm/nodes/core/NodeBuilder.js
+1 −1 examples/jsm/nodes/core/TempNode.js
+0 −6 examples/jsm/nodes/utils/ArrayElementNode.js
+53 −0 examples/jsm/nodes/utils/StorageArrayElementNode.js
+14 −3 examples/jsm/utils/SkeletonUtils.js
+ examples/screenshots/webgl_instancing_morph.jpg
+0 −5 examples/webgl_camera.html
+195 −0 examples/webgl_instancing_morph.html
+1 −8 manual/zh/optimize-lots-of-objects-animated.html
+4 −5 manual/zh/shadows.html
+27 −27 package-lock.json
+1 −0 package.json
+1 −5 src/constants.js
+1 −10 src/core/RenderTarget.js
+2 −2 src/extras/curves/EllipseCurve.js
+0 −4 src/loaders/DataTextureLoader.js
+0 −1 src/loaders/ObjectLoader.js
+35 −0 src/objects/InstancedMesh.js
+0 −1 src/objects/Mesh.js
+1 −10 src/renderers/WebGLCubeRenderTarget.js
+9 −16 src/renderers/WebGLRenderer.js
+2 −0 src/renderers/shaders/ShaderChunk.js
+1 −1 src/renderers/shaders/ShaderChunk/map_fragment.glsl.js
+14 −0 src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js
+11 −2 src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js
+2 −0 src/renderers/shaders/ShaderLib/depth.glsl.js
+2 −0 src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/linedashed.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/meshbasic.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/meshlambert.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/meshmatcap.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/meshnormal.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/meshphong.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/meshphysical.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/meshtoon.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/points.glsl.js
+1 −0 src/renderers/shaders/ShaderLib/shadow.glsl.js
+15 −8 src/renderers/webgl/WebGLMorphtargets.js
+7 −0 src/renderers/webgl/WebGLProgram.js
+19 −16 src/renderers/webgl/WebGLPrograms.js
+1 −29 src/textures/Texture.js
5 changes: 5 additions & 0 deletions types/three/src/objects/InstancedMesh.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Box3 } from "../math/Box3.js";
import { Color } from "../math/Color.js";
import { Matrix4 } from "../math/Matrix4.js";
import { Sphere } from "../math/Sphere.js";
import { DataTexture } from "../textures/DataTexture.js";
import { Mesh } from "./Mesh.js";

export interface InstancedMeshEventMap extends Object3DEventMap {
Expand Down Expand Up @@ -82,6 +83,8 @@ export class InstancedMesh<
*/
instanceMatrix: InstancedBufferAttribute;

morphTexture: DataTexture | null;

/**
* Computes bounding box of the all instances, updating {@link boundingBox | .boundingBox} attribute.
* @remarks Bounding boxes aren't computed by default. They need to be explicitly computed, otherwise they are `null`.
Expand Down Expand Up @@ -126,6 +129,8 @@ export class InstancedMesh<
*/
setMatrixAt(index: number, matrix: Matrix4): void;

setMorphAt(index: number, dummy: Mesh): void;

/**
* No effect in {@link InstancedMesh}.
* @ignore
Expand Down
1 change: 1 addition & 0 deletions types/three/src/renderers/webgl/WebGLPrograms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface WebGLProgramParameters {
batching: boolean;
instancing: boolean;
instancingColor: boolean;
instancingMorph: boolean;

supportsVertexTextures: boolean;
outputColorSpace: ColorSpace;
Expand Down

0 comments on commit 9b8afb8

Please sign in to comment.