import { RxValue } from "../controllers/rxValue"; import { PackEnv } from "./pack/PackEnv"; import { PackGeom } from "./pack/PackGeom"; import { PackMat } from "./pack/PackMat"; import { PackProduct } from "./pack/PackProduct"; import { PackScene } from "./pack/PackScene"; export class PackSource { version = "2.0.0"; viewMode = "scene"; state = RxValue.create({ mats: [] as PackMat[], geoms: [] as PackGeom[], env3ds: [] as PackEnv[], products: [] as PackProduct[], scenes: [] as PackScene[], }) userData:any = null; get scenes() { return this.state.scenes; } get mats() { return this.state.mats; } get geoms() { return this.state.geoms; } get env3ds() { return this.state.env3ds; } get products() { return this.state.products; } toJson( ) { const toJson = (item:any)=>item.toJson(); return { version: this.version, viewMode: this.viewMode, userData: this.userData, mats: this.mats.map(toJson), env3ds: this.env3ds.map(toJson), geoms: this.geoms.map(toJson), scenes: this.scenes.map(toJson), products: this.products.map(toJson), } } fromJson(data:any) { this.version = data.version; this.viewMode = data.viewMode; this.userData = data.userData; this.state.env3ds = (data.env3ds||[]).map((item:any)=>{ const s = new PackEnv(); s.fromJson(item); return s; }) this.state.mats = (data.mats||[]).map((item:any)=>{ const s = new PackMat(); s.fromJson(item); return s; }) this.state.geoms = (data.geoms||[]).map((item:any)=>{ const s = new PackGeom(); s.fromJson(item); return s; }) this.state.products = (data.products||[]).map((item:any)=>{ const s = new PackProduct(); s.fromJson(item); return s; }) this.state.scenes = (data.scenes||[]).map((item:any)=>{ const s = new PackScene(); s.fromJson(item); return s; }) } }