Skip to content

6. Adding 3D objects to scene

MYLi edited this page Aug 4, 2023 · 1 revision
const [sceneObject] = await sdk.Scene.createObjects(1);

// add a scene node for the fbx model
const gltfNode = sceneObject.addNode();

// adjust the position of the scene node
gltfNode.obj3D.position.set(0, -0.68, 0);

// add the gltf loader component that loads a parrot model. Adjust the model's scale to make it fit inside the model.
const gltfComponent = gltfNode.addComponent('mp.gltfLoader', {
  url: 'https://cdn.jsdelivr.net/gh/mrdoob/three.js@dev/examples/models/gltf/Parrot.glb',
  localScale: {
      x: 0.03,
      y: 0.03,
      z: 0.03,
  },
});

// add another scene node to contain the light objects.
const lightsNode = sceneObject.addNode();

// Add directional and ambient lights
const directionalLightComponent = lightsNode.addComponent('mp.directionalLight', {
  color: { r: 0.7, g: 0.7, b: 0.7 },
});
lightsNode.addComponent('mp.ambientLight', {
  intensity: 0.5,
  color: { r: 1.0, g: 1.0, b: 1.0 },
});

// Add a path id 'ambientIntensity' to the intensity property of the directional light component.
// The path will be used to set the value later.
const ambientIntensityPath = sceneObject.addInputPath(directionalLightComponent, 'intensity' 'ambientIntensity');

// Start the scene object and its nodes.
sceneObject.start();

Available model types: type: gltf binary component: GLTF_LOADER scale: 0.01 url: https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Duck/glTF-Binary/Duck.glb

type: gltf component: GLTF_LOADER scale: 0.01 url: https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/CesiumMan/glTF/CesiumMan.gltf

type: obj component: OBJ_LOADER scale: 0.01 url: https://github.com/mrdoob/three.js/blob/dev/examples/models/obj/female02/female02.obj materialUrl: https://github.com/mrdoob/three.js/blob/dev/examples/models/obj/female02/female02.mtl

type: dae component: DAE_LOADER scale: 0.3 url: https://github.com/mrdoob/three.js/blob/dev/examples/models/collada/stormtrooper/stormtrooper.dae

type: fbx component: FBX_LOADER scale: 0.00002 url: https://github.com/mrdoob/three.js/blob/dev/examples/models/fbx/stanford-bunny.fbx