Skip to content

Commit

Permalink
fix(composer): Fix camera view positioning under sub model (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwills-jdubs authored Nov 10, 2022
1 parent eabc6aa commit 94dcdda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,20 @@ export const AddObjectMenu = () => {
parentRef: getRefForParenting(),
} as unknown as ISceneNodeInternal;

const parent = getObject3DBySceneNodeRef(node.parentRef);
let physicalParentNode: ISceneNodeInternal | undefined = getSceneNodeByRef(node.parentRef);
while (physicalParentNode && findComponentByType(physicalParentNode, KnownComponentType.SubModelRef)) {
physicalParentNode = getSceneNodeByRef(physicalParentNode.parentRef);
}

const hierarchicalParentRef = node.parentRef;
const parent = physicalParentNode ? getObject3DBySceneNodeRef(physicalParentNode.ref) : undefined;
const newNode = createNodeWithTransform(
node,
mainCameraObject.position,
mainCameraObject.rotation,
mainCameraObject.scale,
parent,
hierarchicalParentRef,
);

appendSceneNode(newNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Object {
"type": "Camera",
},
],
"parentRef": "parent-ref",
"ref": "test-ref",
"transform": Object {
"position": Array [
Expand Down Expand Up @@ -35,6 +36,7 @@ Object {
"type": "Camera",
},
],
"parentRef": undefined,
"ref": "test-ref",
"transform": Object {
"position": Array [
Expand Down
2 changes: 2 additions & 0 deletions packages/scene-composer/src/utils/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ export const createNodeWithTransform = (
rotation: THREE.Euler,
scale: THREE.Vector3,
parent?: THREE.Object3D,
targetRef?: string,
): ISceneNodeInternal => {
const finalTransform = getFinalTransform({ position, rotation, scale }, parent);

const node = (newWidget as AddingWidgetInfo).node ? (newWidget as AddingWidgetInfo).node : newWidget;
return {
...node,
parentRef: targetRef || parent?.userData.nodeRef,
transform: {
position: finalTransform.position.toArray(),
rotation: finalTransform.rotation.toVector3().toArray(),
Expand Down

0 comments on commit 94dcdda

Please sign in to comment.