UNPKG

@playcanvas/react

Version:

A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.

54 lines 1.79 kB
import { Entity } from "playcanvas"; function createInstance(_type, props, _app) { const entity = new Entity(props.name); const instance = { type: "entity", entity }; commitUpdate(instance, 'entity', {}, props); return instance; } function commitUpdate(instance, _type, oldProps, newProps) { console.log('commitUpdate', instance, _type, oldProps, newProps); if (newProps.position && Array.isArray(newProps.position)) { instance.entity.setLocalPosition(...newProps.position); } if (newProps.rotation && Array.isArray(newProps.rotation)) { instance.entity.setLocalEulerAngles(...newProps.rotation); } if (newProps.scale && Array.isArray(newProps.scale)) { instance.entity.setLocalScale(...newProps.scale); } } function appendChild(parent, child) { if (parent.type !== 'entity') { console.warn('Cannot attach an entity directly to a component. Wrap it in an <Entity>.'); return; } if (child.type !== 'entity') { console.warn(`Cannot attach an ${child.type} directly to an entity.`); return; } parent.entity.addChild(child.entity); } function appendChildToContainer(container, child) { container.app.root.addChild(child.entity); } function appendInitialChild(parent, child) { appendChild(parent, child); } function removeChild(parent, child) { if (parent.entity && child.entity) { parent.entity.removeChild(child.entity); } } function removeChildFromContainer(container, child) { container.app.root.removeChild(child.entity); } export default { createInstance, commitUpdate, appendChild, appendInitialChild, removeChild, removeChildFromContainer, appendChildToContainer, }; //# sourceMappingURL=entity-config.js.map