Hey all, I’m having an issue with vertex winding order. Please have a look:
- I’m using 's UnrealJS plugingithub.com/ncsoft/Unreal.js which allows a V8 runtime
- I created a blueprint that has variables for vertices, triangles, normals, uvs, and sends it to a procedural mesh
- I extended this BP class in Javascript, and replaced the base-class’s vertices/faces etc with values generated from THREE.js
The BP
The JS code
// Blueprint class can be subclassed!
class ProceduralJSMesh extends Blueprint.Load('/Game/ProceduralBox').GeneratedClass {
// constructor
ctor() {
// Subobject initialization, property initialization
this.bAlwaysRelevant = true
console.log( 'constructing procedural js mesh' );
}
// declare UPROPERTY's here
// ; this.XXXXX/*[attribute+]+type*/;
properties() {
}
ReceiveBeginPlay() {
const geo = new THREE.BoxGeometry( 200, 200, 200, 1, 1, 1 );
this.vertices = geo.faces.reduce( function( arr, f ){
arr.push( threeVertexToUEVertex( geo.vertices f.a ] ) );
arr.push( threeVertexToUEVertex( geo.vertices f.b ] ) );
arr.push( threeVertexToUEVertex( geo.vertices f.c ] ) );
return arr;
}, ] );
this.triangles = geo.faces.reduce( function( arr, f ){
arr.push( f.a );
arr.push( f.b );
arr.push( f.c );
return arr;
}, ] );
this.normals = geo.faces.reduce( function( arr, f ){
arr.push( threeVertexToUEVertex( f.vertexNormals 0 ] ) );
arr.push( threeVertexToUEVertex( f.vertexNormals 1 ] ) );
arr.push( threeVertexToUEVertex( f.vertexNormals 2 ] ) );
return arr;
}, ] );
this.uvs = geo.faceVertexUvs[0].reduce( function( arr, uvs ){
arr.push({
X: uvs[2].x,
Y: uvs[2].y
});
return arr;
}, ] );
super.ReceiveBeginPlay();
console.log( 'vertices length', this.vertices.length );
console.log( 'triangles length', this.triangles.length );
console.log( 'normals length', this.normals.length );
}
The result:
It seems like the vertex ordering is different from THREE.js to Unreal Engine. I’m not really sure why this is, I’ve tried flipping the vertices around, c/b/a, c/a/b, b/a/c, etc… tried basically every combination and still couldn’t get the correct vertex ordering. It also seems like the triangles are not selecting the correct vertices.
So I tried another experiment, much simpler this time.
Assuming we have vertices here:
0,0+---------------------------+200,0
++ +
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
+-------------------------------+
0,200 200,200
We can construct the faces like so:
geo.vertices.push( new THREE.Vector3(0,0,0), new THREE.Vector3(0,200,0), new THREE.Vector3(200,200,0) );
geo.vertices.push( new THREE.Vector3(0,0,0), new THREE.Vector3(200,0,0), new THREE.Vector3(200,200,0) );
geo.faces.push( new THREE.Face3( 0, 1, 2 ) );
geo.faces.push( new THREE.Face3( 3, 4, 5 ) );
However here’s what happens:
If we flip the vertices like this (note the second set of vertices, the 2nd and 3rd are swapped)
geo.vertices.push( new THREE.Vector3(0,0,0), new THREE.Vector3(0,200,0), new THREE.Vector3(200,200,0) );
geo.vertices.push( new THREE.Vector3(0,0,0), new THREE.Vector3(200,200,0), new THREE.Vector3(200,0,0) );
Then we’ve got the correct order?
I don’t really understand what’s happening here. Note that I’m still very beginner at UE so please bare with me. I need help!
Is there anything I can check between the verts to ensure the correct vertex ordering or normal facing?