AFRAME.registerComponent("glb-model",
{ schema:{ model_url: {type:
"string", default: ""}, scale: {type: "string", default: "1 1 1"} }, init:
function(){ var sceneEl = document.querySelector("a-scene"); var assetsEl
= document.querySelector("a-assets");
//if a-assets tag is not created by
the user, create the tag here
if (assetsEl == null) { assetsEl =
document.createElement("a-assets"); sceneEl.appendChild(assetsEl); }
//set
up 3D model asset
var model_asset_el =
document.createElement("a-asset-item"); model_asset_el.setAttribute("id",
"glb_model_asset"); model_asset_el.setAttribute( "src",
this.data.model_url ); assetsEl.appendChild(model_asset_el);
//add the 3D
model asset to the scene
var model_entity_el =
document.createElement("a-entity"); model_entity_el.setAttribute("id",
"glb_model"); model_entity_el.setAttribute( "gltf-model",
"#glb_model_asset" ); model_entity_el.setAttribute("scale",
this.data.scale); sceneEl.appendChild(model_entity_el); } })