Refactor getTransformTargetOrientation method in viewport-host.ts
This commit is contained in:
@@ -1473,39 +1473,41 @@ export class ViewportHost {
|
|||||||
private getTransformTargetOrientation(
|
private getTransformTargetOrientation(
|
||||||
session: ActiveTransformSession
|
session: ActiveTransformSession
|
||||||
): Quaternion | null {
|
): Quaternion | null {
|
||||||
switch (session.target.kind) {
|
const target = session.target;
|
||||||
|
const preview = session.preview;
|
||||||
|
|
||||||
|
switch (target.kind) {
|
||||||
case "brush":
|
case "brush":
|
||||||
if (session.preview.kind !== "brush") {
|
if (preview.kind !== "brush") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.createRotationQuaternion(session.preview.rotationDegrees);
|
return this.createRotationQuaternion(preview.rotationDegrees);
|
||||||
case "brushes":
|
case "brushes":
|
||||||
if (session.preview.kind !== "brushes") {
|
if (preview.kind !== "brushes") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeBrushPreview = session.preview.items.find(
|
const activeBrushPreview = preview.items.find(
|
||||||
(item) => item.brushId === session.target.activeBrushId
|
(item) => item.brushId === target.activeBrushId
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.createRotationQuaternion(
|
return this.createRotationQuaternion(
|
||||||
activeBrushPreview?.rotationDegrees ?? { x: 0, y: 0, z: 0 }
|
activeBrushPreview?.rotationDegrees ?? { x: 0, y: 0, z: 0 }
|
||||||
);
|
);
|
||||||
case "modelInstance":
|
case "modelInstance":
|
||||||
if (session.preview.kind !== "modelInstance") {
|
if (preview.kind !== "modelInstance") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.createRotationQuaternion(session.preview.rotationDegrees);
|
return this.createRotationQuaternion(preview.rotationDegrees);
|
||||||
case "modelInstances":
|
case "modelInstances":
|
||||||
if (session.preview.kind !== "modelInstances") {
|
if (preview.kind !== "modelInstances") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeModelInstancePreview = session.preview.items.find(
|
const activeModelInstancePreview = preview.items.find(
|
||||||
(item) =>
|
(item) => item.modelInstanceId === target.activeModelInstanceId
|
||||||
item.modelInstanceId === session.target.activeModelInstanceId
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.createRotationQuaternion(
|
return this.createRotationQuaternion(
|
||||||
@@ -1514,36 +1516,36 @@ export class ViewportHost {
|
|||||||
case "pathPoint":
|
case "pathPoint":
|
||||||
return null;
|
return null;
|
||||||
case "entity":
|
case "entity":
|
||||||
if (session.preview.kind !== "entity") {
|
if (preview.kind !== "entity") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (session.preview.rotation.kind) {
|
switch (preview.rotation.kind) {
|
||||||
case "yaw":
|
case "yaw":
|
||||||
return this.createRotationQuaternion({
|
return this.createRotationQuaternion({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: session.preview.rotation.yawDegrees,
|
y: preview.rotation.yawDegrees,
|
||||||
z: 0
|
z: 0
|
||||||
});
|
});
|
||||||
case "direction":
|
case "direction":
|
||||||
return new Quaternion().setFromUnitVectors(
|
return new Quaternion().setFromUnitVectors(
|
||||||
new Vector3(0, 1, 0),
|
new Vector3(0, 1, 0),
|
||||||
new Vector3(
|
new Vector3(
|
||||||
session.preview.rotation.direction.x,
|
preview.rotation.direction.x,
|
||||||
session.preview.rotation.direction.y,
|
preview.rotation.direction.y,
|
||||||
session.preview.rotation.direction.z
|
preview.rotation.direction.z
|
||||||
).normalize()
|
).normalize()
|
||||||
);
|
);
|
||||||
case "none":
|
case "none":
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case "entities":
|
case "entities":
|
||||||
if (session.preview.kind !== "entities") {
|
if (preview.kind !== "entities") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeEntityPreview = session.preview.items.find(
|
const activeEntityPreview = preview.items.find(
|
||||||
(item) => item.entityId === session.target.activeEntityId
|
(item) => item.entityId === target.activeEntityId
|
||||||
);
|
);
|
||||||
|
|
||||||
if (activeEntityPreview === undefined) {
|
if (activeEntityPreview === undefined) {
|
||||||
@@ -1583,11 +1585,11 @@ export class ViewportHost {
|
|||||||
case "brushFace":
|
case "brushFace":
|
||||||
case "brushEdge":
|
case "brushEdge":
|
||||||
case "brushVertex":
|
case "brushVertex":
|
||||||
if (session.preview.kind !== "brush") {
|
if (preview.kind !== "brush") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.createRotationQuaternion(session.preview.rotationDegrees);
|
return this.createRotationQuaternion(preview.rotationDegrees);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user