Object3D, Mesh, Scene, Group ambiguity

Description of the problem

I’m a little bit confused with the concept of creating a scene graph with three.js, not sure if this should be posted to stack overflow.

Object3D

Base class for scene graph objects.

Scene

Scenes allow you to set up what and where is to be rendered by three.js. This is where you place objects, lights and cameras.

These two make sense for constructing scene graphs, but where does Group fit in, or how is it different than Object3D?

But then Mesh also extends object3d and adds flavor to the mix.

So a minimal graph needed to draw something is

[Scene]->[Mesh]->[Geometry,Material]

But where do object and group fit in

[Scene]->[Group]->[Object3D]->[Mesh]

If object3D has only one child mesh, then that seems reduntant, since mesh is already an object3d and can be positioned. If it has multiple children then it should be a group, if it doesnt have any what is the use case scenario?

Then this concept makes constructing a graph a bit confusing when it comes to loading meshes.

Lets say you want to “draw a box”, and look at the documentation:

var geometry = new THREE.BoxGeometry( 1, 1, 1 ); //geometry instantiated and filled by Box

var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );//material instantiated

var cube = new THREE.Mesh( geometry, material ); //graph node created
scene.add( cube ); //branch created 

All nice and synchronous, geometry and material declared ahead of a mesh, and then a mesh is constructed with them.

But then if you want to load geometry, and you look at the documentation:


// instantiate a loader

var loader = new THREE.JSONLoader();

// load a resource
loader.load(
    // resource URL
    'models/animated/monster/monster.js',
    // Function when resource is loaded
    function ( geometry, materials ) {


        var material = new THREE.MultiMaterial( materials );
        var object = new THREE.Mesh( geometry, material );
        scene.add( object );
    }
);

Since scene already exists, the graph exists. But some time in the future, depending on when a Geometry class gets it’s data, we continue creating the graph.

I’m not sure if it was always possible to instantiate a Mesh without providing an instance of Geometry, it is now so it is possible to add this to a mesh that has already been created.

I’m not sure exactly how to explain the ambiguity here but i think this example illustrates it well. I’m also trying to relate to how Unity handles the scene graph. Their GameObject can have a mesh/rendering component attached, but this entity is not a 3d object.

[Scene]->[Object3D]->[Object3D]->[Objec3D]->[Mesh]

does the mesh here really need to have TRS, and it’s own matrix, i.e. be an object3d?

Three.js version
  • Dev
  • r76
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • Linux
  • Android
  • IOS
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

1 thought on “Object3D, Mesh, Scene, Group ambiguity

  1. THREE.Group (which extends THREE.Object3D) is just a nicer API and it also hints the renderer to not look for geometries or materials inside.

    When dealing with a THREE.Object3D, the renderer doesn’t know if it has a geometry or material, as the object could be, in fact, a THREE.Mesh.

Comments are closed.