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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
944 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;
}
}
2022-08-13 15:12:31 +05:30
changeMaterial(materialKey) {
this.material = materials[materialKey];
2017-08-17 22:00:37 +05:30
}
}