debian-mirror-gitlab/app/assets/javascripts/blob/3d_viewer/mesh_object.js

37 lines
930 B
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
import { Matrix4, MeshLambertMaterial, Mesh } from 'three/build/three.module';
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
const defaultColor = 0xe24329;
2017-08-17 22:00:37 +05:30
const materials = {
default: new MeshLambertMaterial({
color: defaultColor,
}),
wireframe: new MeshLambertMaterial({
color: defaultColor,
wireframe: true,
}),
};
export default class MeshObject extends Mesh {
constructor(geo) {
2018-12-13 13:39:08 +05:30
super(geo, materials.default);
2017-08-17 22:00:37 +05:30
this.geometry.computeBoundingSphere();
this.rotation.set(-Math.PI / 2, 0, 0);
if (this.geometry.boundingSphere.radius > 4) {
const scale = 4 / this.geometry.boundingSphere.radius;
2018-12-13 13:39:08 +05:30
this.geometry.applyMatrix(new Matrix4().makeScale(scale, scale, scale));
2017-08-17 22:00:37 +05:30
this.geometry.computeBoundingSphere();
this.position.x = -this.geometry.boundingSphere.center.x;
this.position.z = this.geometry.boundingSphere.center.y;
}
}
changeMaterial(type) {
this.material = materials[type];
}
}