PolyhedronGeometry or something similar, for constructing a mesh from the coordinates of points in space

Hi all. In the example with the rabbit cannon.js - bunny demo I came across the construction of a grid using coordinate points, here is my code.

var paral = [
{"verts":[1,1,0,
3,1,0,
3,3,0,
1,3,0,
0,0,2,
2,0,2,
2,2,2,
0,2,2],
"faces":[3,6,2,
3,7,6,
0,7,3,
0,4,7,
7,4,5,
7,5,6,
3,1,0,
3,2,1,
0,5,4,
5,0,1,
1,2,6,
1,6,5],
"offset":[-0.6374034157303371,-0.5318040449438204,-0.12628506031460668]}] ;

this is a paralepiped.
I found this in the three js manuals
https://threejs.org/docs/#api/en/geometries/PolyhedronGeometry
here I can’t select anything other than -1 or 1, therefore I only get a cube, is it possible to solve this problem without using OBJLoader

You can create any geometry from coordinate points.
You can specify them as constants or calculate them. Depending on your requirements.

simple from the Collection of examples from discourse.threejs.org
BufferGeometryNonIndexed
BufferGeometryIndexed
advanced
Round-edged box flat
Multi Form Geometry

This option helped me

    let points = [
        new THREE.Vector3(1, 1, 0),
        new THREE.Vector3(3, 1, 0),
        new THREE.Vector3(3, 3, 0),
        new THREE.Vector3(1, 3, 0),
        new THREE.Vector3(0, 0, 2),
        new THREE.Vector3(2, 0, 2),
        new THREE.Vector3(2, 2, 2),
        new THREE.Vector3(0, 2, 2),

    ];

    let faces = [
        new THREE.Face3(3, 6, 2),
        new THREE.Face3(3, 7, 6),
        new THREE.Face3(0, 7, 3),
        new THREE.Face3(0, 4, 7),
        new THREE.Face3(7, 4, 5),
        new THREE.Face3(7, 5, 6),
        new THREE.Face3(3, 1, 0),
        new THREE.Face3(3, 2, 1),
        new THREE.Face3(0, 5, 4),
        new THREE.Face3(5, 0, 1),
        new THREE.Face3(1, 2, 6),
        new THREE.Face3(1, 6, 5),
    ];


    let geometry = new THREE.Geometry();
    geometry.vertices = points;
    geometry.faces = faces;
    geometry.mergeVertices();
const material = new THREE.MeshPhongMaterial({
  color: 0xFF0000,    // red (can also use a CSS color string here)
  flatShading: true,
});
var mesh1=new THREE.Mesh(geometry ,material )


scene.add(mesh1)

Which three.js relese are you using?

three-geometry-will-be-removed-from-core-with-r125

I’m using r116 due to backward compatibility issues

1 Like

It can be difficult to get help on the old geometry, as many developers were working with BufferGeometry way before r125. :thinking:

When I myself started with three.js at r82, I used Geometry first. But following a tip from Mugen87, I also realized my addon
Addon. Produces almost infinite many time-varying geometries with functions
(and others) as indexed and non-indexed buffer geometry. I differentiated between all three versions in one file by selecting them. This makes it easy to see where there are differences or similarities between the versions. Certainly not an easy read, but possibly helpful to transfer something from BufferGeometry to the old geometry.

THREEf.js/THREEf_90/THREEf.js at ff39794dc4a2c33027590bc9b694f0684fcd2dfe · hofk/THREEf.js · GitHub

Compare for downgrade.

function create()

function create()

function morphVertices( time )

function morphVertices( time )

function morphFaces( time )

function vertexFaceNumbersHelper( mesh, mode, size, color )

this.update = function ( mode )