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
926 B
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import { Matrix4, MeshLambertMaterial, Mesh } from 'three';
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;
2022-10-11 01:57:18 +05:30
this.geometry.applyMatrix4(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
}
}