Introducing: The Lattice

haha this thread made my monday morning :slight_smile:
For the experimenters around here, you can also use the Lattice in NGE:
Babylon.js Node Geometry Editor (babylonjs.com)

Cone head :wink:

image

2 Likes

And now with GPU support:
Add shader rendering support for Lattice by deltakosh ยท Pull Request #15700 ยท BabylonJS/Babylon.js (github.com)

// lattice
    var lattice = new BABYLON.Lattice({ 
        resolutionY: 10,
        autoAdaptToMesh: skull, 
        position: BABYLON.Vector3.Zero()
    });

    const latticePlugin = new BABYLON.LatticePluginMaterial(lattice, material);
    
    scene.onBeforeRenderObservable.add(() => {
        // Twist!!
        for (x = 0; x < lattice.resolutionX; x++) {
            for (y = 0; y < lattice.resolutionY; y++) {
                for (z = 0; z < lattice.resolutionZ; z++) {
                    const angle = (y / lattice.resolutionY) * 0.02;
                    const control = lattice.data[x][y][z];
                    const cx = control.x;
                    const cz = control.z;

                    const cosAngle = Math.cos(angle);
                    const sinAngle = Math.sin(angle);

                    // Rotation
                    control.x = cosAngle * cx - sinAngle * cz;
                    control.z = sinAngle * cx + cosAngle * cz;
                }
            }
        }

        // Update texture data
        latticePlugin.refreshData();
    });
2 Likes