Entity re-parenting
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 17.6k
- Forks
- 4.4k
- PR merge metrics
- No merged PRs in 30d
Description
It's helpful to be able to entities to different parents. Currently, to do this, you need to:
- flush entity to DOM (to preserve your entity state).
- copy the entity.
- add copy to new parent entity element.
- remove the existing entity.
var entity = document.querySelector('#myelement');
var newParent = document.querySelector('#mynewparent');
entity.flushToDom();
var copy = entity.cloneNode();
newParent.appendChild(copy);
entity.parentNode.removeChild(entity);
To do this in three.js, it's a simple matter of changing the object3d.parent. DOM parentNode and parentElement are read only properties, so you cannot re-write to a new parent. Not sure if this applies any differently to custom element/web component.
It would be nice to just:
entity.parent = newParent;
Also welcome any suggestions for any alternative way of doing this that I may have missed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by investigating the entity, parent, flushToDom, cloneNode, appendChild, and parentNode behavior described in the issue, including how custom elements or web components handle re-parenting. Done should mean an entity can move to a new parent without flushing, copying, and removing it while preserving its state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, three.js
- Domain
- frontend, game-dev, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100