massive interactive objects refactoring
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { MeshStandardMaterial, MeshBasicMaterial, PlaneGeometry, Mesh, DoubleSide, Vector3 } from "three";
|
||||
|
||||
class ImageObject {
|
||||
constructor(engine, obj) {
|
||||
return new Promise(async(resolve, reject)=>{
|
||||
if (obj.$go){
|
||||
obj.path = engine.assetPath;
|
||||
obj.value = obj.$go.asset.name;
|
||||
}
|
||||
var t = await engine.loadTexture(obj.value, obj.path)
|
||||
var mp = {
|
||||
map: t,
|
||||
alphaTest: 0.5,
|
||||
side: DoubleSide
|
||||
};
|
||||
if (obj.nm) {
|
||||
mp.normalMap = engine.loadTexture(obj.nm, obj.path);
|
||||
}
|
||||
if (obj.em) {
|
||||
mp.emissiveMap = engine.loadTexture(obj.em, obj.path);
|
||||
}
|
||||
if (obj.am) {
|
||||
mp.alphaMap = engine.loadTexture(obj.am, obj.path);
|
||||
}
|
||||
obj.material && Object.assign(mp, obj.material);
|
||||
let geo = new PlaneGeometry(obj.width || 1, obj.height || 1);
|
||||
if (obj.uv) {
|
||||
var uvAttribute = geo.attributes.uv;
|
||||
for (var i = 0; i < uvAttribute.count; i++) {
|
||||
uvAttribute.setXY(i, obj.uv[2 * i], obj.uv[2 * i + 1]);
|
||||
}
|
||||
}
|
||||
this.object = new Mesh(geo, mp.metalness ? new MeshStandardMaterial(mp) : new MeshBasicMaterial(mp));
|
||||
|
||||
resolve(this)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export {ImageObject}
|
||||
Reference in New Issue
Block a user