js/Mobilizing/renderer/3D/three/shape/3D/composite/OutlineMesh.js
import * as THREE from 'three';
import Mesh from "../../Mesh";
import Transform from "../../../scene/Transform";
import Material from "../../../scene/Material";
/**
* OutlineMesh class creates a hiddenline fashioned Mesh from any other Mesh.
*/
export default class OutlineMesh extends Mesh {
/**
* @param {Object} params parameters this can contains the same parameters than Mesh class
* @param {Mesh} params.inputMesh The existing Mesh to use for generate a new edge only Mesh (geometry and material)
*/
constructor({
inputMesh = undefined,
} = {}) {
super(...arguments);
this.inputMesh = inputMesh;
this.material = new Material({ type: "line" });
const edg = this.inputMesh.getNativeObject().clone();
const faces = edg.geometry.faces;
const vertices = edg.geometry.vertices;
const edgGeometry = new THREE.Geometry();
const facesIndices = ["a", "b", "c", "d"];
faces.forEach((f) => {
if (f instanceof THREE.Face3) {
const v1 = vertices[f[facesIndices[0]]];
const v2 = vertices[f[facesIndices[1]]];
const v3 = vertices[f[facesIndices[2]]];
const d1 = v1.distanceTo(v2);
const d2 = v1.distanceTo(v3);
const d3 = v3.distanceTo(v2);
if ((d1 > d2) && (d1 > d3)) {
edgGeometry.vertices.push(v1);
edgGeometry.vertices.push(v3);
edgGeometry.vertices.push(v2);
edgGeometry.vertices.push(v3);
}
else if (d2 > d3) {
edgGeometry.vertices.push(v1);
edgGeometry.vertices.push(v2);
edgGeometry.vertices.push(v3);
edgGeometry.vertices.push(v2);
}
else {
edgGeometry.vertices.push(v1);
edgGeometry.vertices.push(v2);
edgGeometry.vertices.push(v3);
edgGeometry.vertices.push(v1);
}
}
});
this._mesh = new THREE.Line(edgGeometry, this.material._material, THREE.LinePieces);
this.transform = undefined;
this.transform = new Transform(this);
}
}