34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
import { TextureLoader, MeshStandardMaterial, MeshBasicMaterial, PlaneGeometry, Mesh } from "three";
|
|
import { assignParams } from "@/lib/MeshUtils";
|
|
|
|
class ImageObject {
|
|
constructor(obj, context) {
|
|
var t = new TextureLoader().setPath(context.path).load(obj.value);
|
|
//t.encoding = sRGBEncoding;
|
|
var mp = {
|
|
map: t,
|
|
alphaTest: 0.5
|
|
};
|
|
if (obj.nm) {
|
|
mp.normalMap = new TextureLoader().setPath(context.path).load(obj.nm);
|
|
}
|
|
if (obj.em) {
|
|
mp.emissiveMap = new TextureLoader().setPath(context.path).load(obj.em);
|
|
}
|
|
if (obj.am) {
|
|
mp.alphaMap = new TextureLoader().setPath(context.path).load(obj.am);
|
|
}
|
|
obj.material && Object.assign(mp, obj.material);
|
|
let geo = new PlaneGeometry(context.wallSize * (obj.w || 1), context.wallSize * (obj.h || 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));
|
|
assignParams(this.object, obj);
|
|
}
|
|
}
|
|
|
|
export {ImageObject} |