How to Shear a Cube in Three.js
Asked Answered
A

2

10

I wonder if anybody come across this specific problem before. With my basic understanding of how the 3d objects are drawn using webgl and three.js it seems that I cannot find a way to create a paralelipiped (or I think this is how it is called) that does inherit it's geometry from cubegeometry, but doesn't have all angles of 90 degrees.

My goal is to have something like this:

example

The result should be very similiar to what

-moz-transform: skew(0,-45.1deg);

would do for an html element. Can anybody help me find a solution?

I thank you for your consideration.

Administer answered 21/9, 2012 at 19:40 Comment(0)
F
23

What you need to do is create a cube mesh, and then apply a shear matrix to the cube's geometry. The operation distorts the geometry in the way you described.

var geometry = new THREE.BoxGeometry( 5, 5, 5 );

var matrix = new THREE.Matrix4();

matrix.set(   1,   Syx,  Szx,  0,
            Sxy,     1,  Szy,  0,
            Sxz,   Syz,   1,   0,
              0,     0,   0,   1  );

geometry.applyMatrix4( matrix );

Alternatively, see https://mcmap.net/q/1047904/-how-to-shear-a-cube-in-three-js

three.js r.143

Followup answered 21/9, 2012 at 20:30 Comment(1)
Great! That's exactly what it takes to solve the problem. Thank you.Administer
A
3

Three.js r129 introduced an update to Matrix4.makeShear() — authored by @WestLangley

https://threejs.org/docs/#api/en/math/Matrix4.makeShear

const geometry = new THREE.BoxGeometry(5, 5, 5);

const matrix = new THREE.Matrix4();
matrix.makeShear(1, 0, 0, 0, 0, 0);

geometry.applyMatrix4(matrix);
Asuncionasunder answered 24/10, 2021 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.