2021-12-29 16:49:15 -05:00
|
|
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
2021-12-29 21:52:24 -05:00
|
|
|
gapp.register("mesh.model", [
|
2021-12-29 16:49:15 -05:00
|
|
|
"add.three", // dep: add.three
|
|
|
|
|
"moto.license", // dep: moto.license
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
let mesh = self.mesh = self.mesh || {};
|
2021-12-29 21:52:24 -05:00
|
|
|
if (mesh.model) return;
|
2021-12-29 16:49:15 -05:00
|
|
|
|
2021-12-29 21:52:24 -05:00
|
|
|
/** default materials **/
|
2021-12-29 17:20:17 -05:00
|
|
|
mesh.material = {
|
|
|
|
|
solid: new THREE.MeshPhongMaterial({
|
|
|
|
|
transparent: true,
|
|
|
|
|
shininess: 100,
|
|
|
|
|
specular: 0x181818,
|
|
|
|
|
color: 0xffff00,
|
|
|
|
|
opacity: 1
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-29 21:52:24 -05:00
|
|
|
/** 3D model rendered on plaform **/
|
|
|
|
|
mesh.model = class MeshModel {
|
2021-12-29 16:49:15 -05:00
|
|
|
constructor(data) {
|
|
|
|
|
let { file, mesh } = data;
|
|
|
|
|
|
|
|
|
|
if (!mesh) {
|
|
|
|
|
dbug.error(`'${file}' missing mesh data`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 17:20:17 -05:00
|
|
|
this.file = file;
|
|
|
|
|
this.mesh = this.load(mesh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
load(vertices, indices) {
|
|
|
|
|
let geo = new THREE.BufferGeometry();
|
|
|
|
|
if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
|
|
|
|
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
|
|
|
|
geo.setAttribute('normal', undefined);
|
|
|
|
|
let meh = new THREE.Mesh(geo, mesh.material.solid);
|
|
|
|
|
geo.computeFaceNormals();
|
|
|
|
|
geo.computeVertexNormals();
|
|
|
|
|
meh.material.side = THREE.DoubleSide;
|
|
|
|
|
meh.receiveShadow = true;
|
|
|
|
|
meh.castShadow = true;
|
|
|
|
|
meh.renderOrder = 1;
|
|
|
|
|
return meh;
|
2021-12-29 16:49:15 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})();
|