webgl/public/gl/core/Scene.js

38 lines
917 B
JavaScript
Raw Normal View History

2023-01-19 03:43:02 +00:00
export class Scene {
constructor() {
this.map = {}
this.entities = {}
this.materials = {}
}
add(material, entity) {
var arr = this.map[material.id]
if (arr == undefined) {
arr = []
this.materials[material.id] = material
}
if (!arr.includes(entity.id)) {
arr.push(entity.id)
this.entities[entity.id] = entity
}
this.map[material.id] = arr
}
remove(material, entity) {
var arr = this.objects[material.id]
if (arr == undefined) {
return
}
const i = arr.indexOf(entity.id)
if(i > -1) {
arr = arr.splice(i, 1)
delete this.entities[entity.id]
if(arr.length < 1) {
delete this.map[material.id]
delete this.materials[material.id]
}
}
}
}