UNPKG

glam

Version:

Experimental WebGL Engine

55 lines (39 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addChildToNode = addChildToNode; exports.default = add; var _updateTypes = require("./update-types"); var _updateTypes2 = _interopRequireDefault(_updateTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function addChildToNode(scene, graph, parent, child) { if ((typeof child === "undefined" ? "undefined" : _typeof(child)) !== "object") { throw new Error("Only objects are allowed in the scene graph"); } if (graph.parent.get(child)) { throw new Error("The node was already added to the scene graph, it must be removed before adding it somewhere else."); } var children = scene.children(parent); // Add the child/parent relationship children.push(child); graph.parent.set(child, parent); // Update scene flags and counts (0, _updateTypes2.default)(scene, graph, child, "add"); scene.flags.changed = true; } function add(scene, graph, a, b) { var node, child; if (a && b) { node = a; child = b; } else if (a && !b) { node = scene; child = a; } else { throw new Error('Tried to add nothing to the scene.'); } addChildToNode(scene, graph, node, child); return scene; }