0

独自のモデル形式を作成したい。その目的のために、カスタム ジオメトリを作成しようとしています。ジオメトリを正しくインポートできます。バー面の法線をジオメトリに追加してもレンダリングされません。

入力ファイルは次のとおりです。

# Coordinates
    0e+0 0e+0 0e+0
    1e+0 0e+0 0e+0
    1e+0 0e+0 1e+0
    0e+0 0e+0 1e+0
    0e+0 1e+0 0e+0
    1e+0 1e+0 0e+0
    1e+0 1e+0 1e+0
    0e+0 1e+0 1e+0
# Normals
0e+0 0e+0 -1e+0
0e+0 -1e+0 0e+0
0e+0 0e+0 1e+0
0e+0 1e+0 0e+0
1e+0 0e+0 0e+0
-1e+0 0e+0 0e+0

# Connectivity List
1 2 6 5
1 2 3 4
3 4 8 7
6 5 8 7
2 6 7 3
1 5 8 4

これが私がそれをインポートする方法です。

    var geometry = new THREE.Geometry();

    //Add all positions to geometry
    for (var g=0;g<coordinates.length;g++){
        geometry.vertices.push(coordinates[g]);

    }

    for(var l=0;l<connectivity.length;l++){

        //sml file have rectangular faces but three js uses triangular faces (THREE.Face4 is deprecated) so converting 4 vertex faces to 3 verex faces 
        var index0= connectivity[l][3]-1;
        var index1= connectivity[l][4]-1;
        var index2= connectivity[l][5]-1;
        var index3= connectivity[l][6]-1;

        //If normals is exist thenaddthem to face array too

        if(normals.length==connectivity.length){

            console.log("Normals are exist");

            var face0=  new THREE.Face3(index0,index1,index2); 
            face0.normal.set(normals[l]);

            geometry.faces.push(face0);

            var face1=  new THREE.Face3(index2,index3,index0);
            face1.normal.set(normals[l]);

            geometry.faces.push(face1); 

        } else{

            console.log("Normals are not exist");

            var face0=  new THREE.Face3(index0,index1,index2);
            geometry.faces.push(face0);
            var face1= new THREE.Face3(index2,index3,index0);

            geometry.faces.push(face1); 
        }
    }

    geometry.computeBoundingBox();
    // geometry.compteVertexNormals();
    geometry.computeFaceNormals();

コードでは、FACE4 が thee.js によって廃止されている間、面 (接続リスト) 配列の四角形を三角形に変換しています。そして、同じクワッドを共有する両方の三角形に同じ法線を割り当てています。

このボックスのレンダリング方法は次のとおりです。

ボックス レンダー

何か不足していますか?

4

1 に答える 1

0

次の行は、正しい構文を使用していません。

face0.normal.set(normals[l]);
...
face1.normal.set(normals[l]);

Face3.normalは でVector3Vector3.set3 つのパラメータを取ります

、、およびプロパティnormals[l]がある場合:xyz

face0.normal.set(normals[l].x, normals[l].y, normals[l].z);

正しく設定します。

または、法線を としてコンストラクターVector3に渡すこともできます。詳細については、こちらのドキュメントを参照してください。Face3

新しい情報に基づく:

normals[l]はすでに であるため、代わりにVector3次を使用する必要があります。Vector3.copyset

face0.normal.copy(normals[l]);

はいえ、これであるためVector3、上記で述べたように、実際にはコンストラクターに含める必要があります。

于 2017-10-02T15:54:04.050 に答える