1

私は自分のthree.jsジオメトリを構築しようとしています。ただし、次のように定義しようとすると、次のようになります。

geometry = new THREE.FreeWallGeometry( 3, 5 );

addSelfthree.jsの行714の関数から「TypeError:visundefined」というエラーが表示されます。

このエラーの原因を見つけるにはどうすればよいですか?

これは私の自家製ジオメトリの現在のコードです:

define(
    [   "libs/three.js/build/three",
    ],
    function (
        three
        ) {

        console.log("setting up makeControls. regards, makeControls");

        //THREE.FreeWallGeometry = function ( length, height, depth, segmentsWidth, segmentsHeight, segmentsDepth, materials, sides ) {

        // X = length, Y = height, Z = depth,
        THREE.FreeWallGeometry = function ( noOfSegments, segmentLength ) {

            THREE.Geometry.call( this );

            var t1, t2,
            normal = new THREE.Vector3( 0, 0, 1);
            freePlane;

            var freePlane = function ( self, parametricPlane_X, parametricPlane_Y, parametricPlane_Z, equidistantSampler_T1, equidistantSampler_T2 ) {

                for ( t2 = 0; t2 < noOfSegments; t2 ++ ) {

                    for ( t1 = 0; t1 < noOfSegments; t1 ++ ) {

                        console.log("free: t1, t2 ", t1, t2);
                        //var x = t1 * segmentT1_length - length_half;
                        //var y = t2 * segmentT2_length - height_half;
                        var x = parametricPlane_X ( t1, t2 );
                        var y = parametricPlane_Y ( t1, t2 );
                        var z = parametricPlane_Z ( t1, t2 );

                        console.log("free: x, y z ", x, y, z);

                        self.vertices.push( new THREE.Vector3( x, - y, z ) );

                    }

                }

                for ( t2 = 0; t2 < noOfSegments; t2 ++ ) {

                    for ( t1 = 0; t1 < noOfSegments; t1 ++ ) {

                        var a = t1 + noOfSegments * t2;
                        var b = t1 + noOfSegments * ( t2 + 1 );
                        var c = ( t1 + 1 ) + noOfSegments * ( t2 + 1 );
                        var d = ( t1 + 1 ) + noOfSegments * t2;



                        //console.log ("free: a, b, c, d ", a, b, c, d);

                        var face = new THREE.Face4( a, b, c, d );

                        if (!self.vertices[face.a]) {
                            console.log("this face.a can't index vertices: ", face.a);
                        }

                        if (!self.vertices[face.b]) {
                            console.log("this face.b can't index vertices: ", face.b);
                        }

                        if (!self.vertices[face.c]) {
                            console.log("this face.c can't index vertices: ", face.c);
                        }

                        if (!self.vertices[face.d]) {
                            console.log("this face.d can't index vertices: ", face.d);
                        }

                        face.normal.copy( normal );
                        face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );

                        self.faces.push( face );
                        self.faceVertexUvs[ 0 ].push( [
                            new THREE.UV( t1 / noOfSegments, 1 - t2 / noOfSegments ),
                            new THREE.UV( t1 / noOfSegments, 1 - ( t2 + 1 ) / noOfSegments ),
                            new THREE.UV( ( t1 + 1 ) / noOfSegments, 1 - ( t2 + 1 ) / noOfSegments ),
                            new THREE.UV( ( t1 + 1 ) / noOfSegments, 1 - t2 / noOfSegments )
                        ] );

                    }

                }

            }


            var parametricPlane_X = function ( t1, t2 ) {
                x = t1;
                return x;
            };

            var parametricPlane_Y = function ( t1, t2 ) {
                y = t1;
                return y;
            };

            var parametricPlane_Z = function ( t1, t2 ) {
                z = t1 * t2;
                return z;
            };

            var equidistantSampler_T1 = function ( t1 ) {
                t1 = Math.sqrt(t1);
                return t1;
            };

            var equidistantSampler_T2 = function ( t2 ) {
                t2 = t2;
                return t2;
            };

            freePlane(this, parametricPlane_X, parametricPlane_Y, parametricPlane_Z, equidistantSampler_T1, equidistantSampler_T2);


            this.computeCentroids();

        };

        THREE.FreeWallGeometry.prototype = Object.create( THREE.Geometry.prototype );

    }
);
4

1 に答える 1

2

Firebugsconsole.trace()を使用して、クラッシュサイトの前に行われた呼び出しを確認できます。

これが一般的に当てはまるかどうかはわかりませんが、あなたの場合、console.trace()への呼び出しの前の最後の関数呼び出しは、の4939行目あたりで定義されaddSelfた関数への呼び出しであったことがわかります。computeCentroidsthree.js

この関数では、vertices-array(カスタムジオメトリの定義が定義されたときに頂点で満たされる)は、、、およびによってインデックス付けface.aされface.bます。face.cface.d

これらのインデックスは、ジオメトリのfaces配列(カスタムジオメトリ定義にも入力したもの)から取得され、ここで問題が発生する可能性があります。

面は頂点で構成されており、生成する頂点が生成する面の頂点インデックスと一致しない場合、面の頂点インデックスの一部が頂点配列の範囲外になる可能性があります。したがってvertices[face.outOfBoundVerticeIndex]、頂点の代わりにnullが返され、バグを見つけるのが困難になります。

PS。Firefoxがトレース呼び出しで溢れるのを防ぐために、未定義をconsole.trace条件として呼び出しを行うことをお勧めします。vこれはFirefoxをひざまずく傾向があります。

于 2012-10-26T17:41:44.163 に答える