Skip to content

Commit

Permalink
feat(event-display): display size on selection
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Dec 22, 2020
1 parent b7e8da0 commit 6943f79
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/phoenix-event-display/src/three/import-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DoubleSide, Mesh, LineSegments, LineBasicMaterial, MeshPhongMaterial, Object3D, Plane, Material, ObjectLoader, Color, FrontSide } from 'three';
import { DoubleSide, Mesh, LineSegments, LineBasicMaterial, MeshPhongMaterial, Object3D, Plane, Material, ObjectLoader, Color, FrontSide, Vector3, Box3 } from 'three';
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { LoadingManager } from '../managers/loading-manager';
Expand Down Expand Up @@ -94,7 +94,7 @@ export class ImportManager {
setFlat: boolean
): Object3D {
object.name = name;
object.userData = { name };
object.userData = { name, color };
return this.setObjFlat(object, color, doubleSided, setFlat);
}

Expand Down Expand Up @@ -122,6 +122,7 @@ export class ImportManager {
if (child instanceof Mesh) {
child.name = object3d.name;
child.userData = object3d.userData;
child.userData.size = this.getObjectSize(child);
// Use the new material
if (child.material instanceof Material) {
child.material.dispose();
Expand Down Expand Up @@ -272,6 +273,7 @@ export class ImportManager {
geometry.traverse((child) => {
if (child instanceof Mesh) {
child.name = child.userData.name = name;
child.userData.size = this.getObjectSize(child);
if (child.material instanceof Material) {
const color = child.material['color'] ? child.material['color'] : 0x2fd691;
const side = doubleSided ? DoubleSide : child.material['side'];
Expand All @@ -291,4 +293,16 @@ export class ImportManager {
}
});
}

/**
* Get the size of object.
* @param object Object to get the size of.
* @returns The size of object as a vector string.
*/
private getObjectSize(object: Mesh): string {
const size = new Vector3();
object.geometry.computeBoundingBox();
object.geometry?.boundingBox?.getSize(size);
return JSON.stringify(size, null, 2);
}
}

0 comments on commit 6943f79

Please sign in to comment.