Search code examples
javascriptaframe

dynamically load aframe entities


I´m building an aframe application, which can dynamically load s from a webservice based on user interaction. These entities are available in text-form. What I need is a way to inject these into the aframe DOM, so that the entities are immediately visible. Is there a way to accomplish this? Neither Google nor the Aframe documentation could help me yet.


Solution

  • You can create and configure the entities individually using document.createElement / setAttribute / appendChild. There's a section in the docs devoted to it.

    You can also manipulate the innerHTML value directly:

    el.innerHMTL = "<a-entity> <a-sphere></a-sphere> <a-light></a-light> </a-entity>"
    

    None of the above it is A-Frame specific, you just use the regular DOM APIs to compose your scene