|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import * as THREE from 'three';
|
|
|
|
|
|
|
|
|
|
import { Material, MeshPhysicalMaterial } from "three";
|
|
|
|
|
|
|
|
|
|
export const MaterialNeedUpdateKey = "needUpdateImg";
|
|
|
|
|
|
|
|
|
@ -9,17 +8,17 @@ export const MaterialNeedUpdateKey = "needUpdateImg";
|
|
|
|
|
export class MaterialDictionary
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
MaterialDict: Map<number, THREE.Material>;
|
|
|
|
|
MaterialDict: Map<number, Material>;
|
|
|
|
|
MaterialCallback: Map<number, any>;
|
|
|
|
|
private _cout = 0;//Id 分配器.
|
|
|
|
|
constructor()
|
|
|
|
|
{
|
|
|
|
|
this.MaterialDict = new Map<number, THREE.Material>();
|
|
|
|
|
this.MaterialDict = new Map<number, Material>();
|
|
|
|
|
this.MaterialCallback = new Map<number, any>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加材质..
|
|
|
|
|
addMaterial(mat: THREE.Material)
|
|
|
|
|
addMaterial(mat: Material)
|
|
|
|
|
{
|
|
|
|
|
this.extendObservable(mat, this._cout);
|
|
|
|
|
this.MaterialDict.set(this._cout, mat);
|
|
|
|
@ -27,11 +26,11 @@ export class MaterialDictionary
|
|
|
|
|
}
|
|
|
|
|
createMaterial()
|
|
|
|
|
{
|
|
|
|
|
let mat = new THREE.MeshPhysicalMaterial({ roughness: 0.2, metalness: 0.2, bumpScale: 0.0005 });
|
|
|
|
|
let mat = new MeshPhysicalMaterial({ roughness: 0.2, metalness: 0.2, bumpScale: 0.0005 });
|
|
|
|
|
mat.name = "材质" + this._cout;
|
|
|
|
|
this.addMaterial(mat);
|
|
|
|
|
}
|
|
|
|
|
extendObservable(mat: THREE.Material, id: number)
|
|
|
|
|
extendObservable(mat: Material, id: number)
|
|
|
|
|
{
|
|
|
|
|
// let mobxData: Object = {};
|
|
|
|
|
|
|
|
|
@ -41,7 +40,7 @@ export class MaterialDictionary
|
|
|
|
|
// for (let key of colorList)
|
|
|
|
|
// {
|
|
|
|
|
// let newKey = "mobx_" + key;
|
|
|
|
|
// mobxData[newKey] = "#" + (mat[key] as THREE.Color).getHexString();
|
|
|
|
|
// mobxData[newKey] = "#" + (mat[key] as Color).getHexString();
|
|
|
|
|
// }
|
|
|
|
|
// for (let d of ["name", "transparent", "roughness", "metalness", "opacity", "depthTest", "map", "bumpMap", "bumpScale", "roughnessMap"])
|
|
|
|
|
// {
|
|
|
|
@ -56,14 +55,14 @@ export class MaterialDictionary
|
|
|
|
|
// {
|
|
|
|
|
// for (let key of colorList)
|
|
|
|
|
// {
|
|
|
|
|
// (mat[key] as THREE.Color).set(mat["mobx_" + key])
|
|
|
|
|
// (mat[key] as Color).set(mat["mobx_" + key])
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// this.MaterialCallback.set(id, mobxRemove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getMaterial(id: number): THREE.Material
|
|
|
|
|
getMaterial(id: number): Material
|
|
|
|
|
{
|
|
|
|
|
return this.MaterialDict.get(Number(id));
|
|
|
|
|
}
|
|
|
|
@ -74,4 +73,4 @@ export class MaterialDictionary
|
|
|
|
|
if (callback) callback();
|
|
|
|
|
this.MaterialCallback.delete(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|