Skip to content

Commit 3ae7274

Browse files
authored
fixed animated picking (#2925)
* fixed animated picking * restrict bounds removal to skinned meshes
1 parent 5653e58 commit 3ae7274

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

packages/model-viewer/src/three-components/gltf-instance/ModelViewerGLTFInstance.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import {FrontSide, Material, Mesh, MeshStandardMaterial, Object3D, Texture} from 'three';
16+
import {FrontSide, Material, Mesh, MeshStandardMaterial, Object3D, Sphere, Texture} from 'three';
1717
import {GLTF} from 'three/examples/jsm/loaders/GLTFLoader.js';
1818

1919
import {$clone, $prepare, $preparedGLTF, GLTFInstance, PreparedGLTF} from '../GLTFInstance.js';
@@ -48,6 +48,8 @@ export class ModelViewerGLTFInstance extends GLTFInstance {
4848

4949
const {scene} = prepared;
5050

51+
const nullSphere = new Sphere(undefined, Infinity);
52+
5153
scene.traverse((node: Object3D) => {
5254
// Set a high renderOrder while we're here to ensure the model
5355
// always renders on top of the skysphere
@@ -63,8 +65,17 @@ export class ModelViewerGLTFInstance extends GLTFInstance {
6365
if (!node.name) {
6466
node.name = node.uuid;
6567
}
66-
if ((node as Mesh).isMesh) {
67-
node.castShadow = true;
68+
const mesh = node as Mesh;
69+
if (mesh.isMesh) {
70+
mesh.castShadow = true;
71+
if ((mesh as any).isSkinnedMesh) {
72+
// Akin to disablig frustum culling above, we have to also manually
73+
// disable the bounds to make raycasting correct for skinned meshes.
74+
mesh.geometry.boundingSphere = nullSphere;
75+
// The bounding box is set in GLTFLoader by the accessor bounds, which
76+
// are not updated with animation.
77+
mesh.geometry.boundingBox = null;
78+
}
6879
}
6980
});
7081

packages/space-opera/src/components/model_viewer_snippet/reducer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export function dispatchExtraAttributes(attributes: any) {
5050
export const getExtraAttributes = (state: State): any =>
5151
state.entities.modelViewerSnippet.extraAttributes;
5252

53-
export function extraAttributesReducer(state: any = {}, action: Action): any {
53+
export function extraAttributesReducer(
54+
state: any = INITIAL_STATE.entities.modelViewerSnippet.extraAttributes,
55+
action: Action): any {
5456
switch (action.type) {
5557
case SET_EXTRA_ATTRIBUTES:
5658
return action.payload;

packages/space-opera/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const INITIAL_STATE: State = {
133133
hotspots: [],
134134
relativeFilePaths:
135135
{posterName: 'poster.webp', environmentName: 'neutral'},
136-
extraAttributes: {},
136+
extraAttributes: {bounds: 'tight'},
137137
},
138138
},
139139
};

0 commit comments

Comments
 (0)