[feature] scaling Geometry rather than Mesh and it’s children.

To change the size of a geometry somewhere in a scene graph, without affecting it’s children, I am doing something like this:

        mesh.geometry.dispose() // rid the old one
        mesh.geometry = new SomeGeometry( /* new size values here */ )

It is possible to achieve the same thing using scale, which would perform better. However, scale can only be set once, when the geometry is created, so that doesn’t help get the performance boost.

The code would look like this:

        const scale = { /* scale values to mimic size change */ }
        mesh.geometry.scale.x = scale.x
        mesh.geometry.scale.y = scale.y
        mesh.geometry.scale.z = scale.z

As the docs mention, this doesn’t work.

If we scale the mesh:

        const scale = { /* scale values to mimic size change */ }
        mesh.scale.x = scale.x
        mesh.scale.y = scale.y
        mesh.scale.z = scale.z

then this affects all children, which is what I want to avoid.

Use case:

I’ve made some custom elements similar to A-Frame. I can do this:

        <i-scene experimental-webgl="true">

                has="box-geometry basic-material"
                size="2 2 2"
                rotation="30 30 30"
                color="0.5 0.5 0.5 1">

                <h1> Hello "mixed mode" </h1>
                   This is DOM content, mixed with WebGL,
                   similar to <a>http://jsfiddle.net/trusktr/jc6j1wmf</a>

                <i-mesh id="second"
                    has="sphere-geometry basic-material"
                    size="1 1 1"
                    rotation="30 30 30"
                    color="0.5 0.5 0.5 1"
                    position="1.5 1.5 0" >


This renders a scene using Three.js and CSS3D, mixing DOM with WebGL. Changing the size attributes works: internally it creates a new geometry with a new size.

Sizing with these elements is a unique feature for these elements. For example, we can write stuff like this:

                <i-mesh id="second"
                    has="sphere-geometry basic-material"
                    sizeMode="literal proportional literal"
                    size="2 0.75 3">

where sizeMode specifies the size mode per axis, which causes size values for each axis to have different meaning. “literal” size mode for a given axis means the value dictates the literal size of the object (without affecting it’s children), and “proportional’ size means that the object’s size is proportional to its parent.

So in that example, the mesh has a literal X size of 2, a Y size of 75%% of its parent, and a literal Z size of 3.

(other size modes are coming soon, which allow for really cool tricks!)

TLDR, I just want to make sizing more performant in certain cases and somehow let the user choose the type of size application (scale vs new vertices). In some cases, scale might be nice, and boost performance. In other cases, scale might have unwanted effect on textures, so resizing the geometry might be better (but expensive). Or maybe we can scale both geometry and texture.

Author: Fantashit

1 thought on “[feature] scaling Geometry rather than Mesh and it’s children.

Comments are closed.