UNPKG

glam

Version:

Experimental WebGL Engine

62 lines (46 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateTypes = updateTypes; exports.default = updateTypesIfRooted; var _isRooted = require("./is-rooted"); var _isRooted2 = _interopRequireDefault(_isRooted); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var BLANK = []; /* * The scene graph is a tree structure, which can be hard to work with at times. * This file sets the scene.types to a flattened list of nodes by type. Each node * can have multiple types to boil down to. */ function updateTypes(scene, graph, node, addOrRemove) { var types = node.type || BLANK; for (var i = 0; i < types.length; i++) { var type = types[i]; var list = graph.types[type]; if (!graph.types[type]) { list = []; graph.types[type] = list; } if (type === "light") { scene.flags.lightsChanged = true; } if (addOrRemove === "add") { list.push(node); } else { var index = list.indexOf(node); if (index !== -1) { list.splice(index, 1); } } } // Recurse var children = scene.children(node); for (var i = 0; i < children.length; i++) { updateTypes(scene, graph, children[i], addOrRemove); } } function updateTypesIfRooted(scene, graph, node, addOrRemove) { if ((0, _isRooted2.default)(scene, graph, node)) { updateTypes(scene, graph, node, addOrRemove); } }