Skip to content

Latest commit

 

History

History

scene-graph

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Scene Graph

A graphical scene is made up of a hierarchy of objects called a "scene graph", A scene graph is a "tree" structure containing the objects that specify what will be rendered on screen.

A browser's Document Object Model (DOM) is a scene graph that has traditionally been used for 2D graphics. LUME brings 3D to the DOM, or shall we say, LUME brings the DOM into the future. 😎

💡Tip

The DOM is a tree of HTML elements that are in a web page. Here's Mozilla's introduction to the DOM.

The following graphic shows the idea of a hierarchical tree. The graphic itself is created with a tree of (Lume) elements (a scene graph) that defines the following visual depicting the concept of a scene graph.

<style> html, body { width: 100%; height: 100%; } lume-scene { user-select: none; } .line { background: black; } lume-element3d:not(.line) { font-family: sans-serif; background: skyblue; border-radius: 3px; } lume-element3d div { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } </style>
Scene
Node
Node
Node
Node

The top-level node in a LUME scene is always a <lume-scene> element. The <lume-scene> element creates an area in which we'll render LUME-based graphics. Below the scene element are other types of elements that render in different visual ways.

This next example shows how parent elements affect the positioning of child elements. The positions and rotations of the child <lume-element3d> elements are relative to their parent <lume-element3d> elements. This is why the parent-most element only rotates but does not move to other positions, while each child not only rotates but also moves due to the rotation of its parent.

<script> // Note, Docsify does not currently support script type="module", so we use // the import() function instead of regular import syntax. import('lume').then(Lume => { document.querySelectorAll('lume-scene *').forEach(n => { if (n instanceof Lume.Element3D) { // FIXME temporary hack to trigger a re-render because transforms are not // updated on the initial paint. n.rotation.y += 0.000000001 n.addEventListener('pointerover', event => { console.log('on a node!') n.scale.x = 1.1 n.scale.y = 1.1 n.scale.z = 1.1 }) n.addEventListener('pointerout', event => { n.scale.x = 1 n.scale.y = 1 n.scale.z = 1 }) } }) }) </script>