Javascript three.js:“;TypeError:v未定义";定义自制几何图形时
我正在尝试构建自己的three.js几何体。但是,当我试图定义它时,如下所示:Javascript three.js:“;TypeError:v未定义";定义自制几何图形时,javascript,firebug,three.js,Javascript,Firebug,Three.js,我正在尝试构建自己的three.js几何体。但是,当我试图定义它时,如下所示: geometry = new THREE.FreeWallGeometry( 3, 5 ); 我从three.js中第714行的函数addSelf中得到错误“TypeError:v未定义” 如何找出触发此错误的原因 这是我自制几何体的当前代码: define( [ "libs/three.js/build/three", ], function ( three
geometry = new THREE.FreeWallGeometry( 3, 5 );
我从three.js中第714行的函数addSelf
中得到错误“TypeError:v未定义”
如何找出触发此错误的原因
这是我自制几何体的当前代码:
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 );
}
);
定义(
[“libs/three.js/build/three”,
],
作用(
三
) {
log(“设置makeControls.alives,makeControls”);
//三.自由墙几何=功能(长度、高度、深度、分段宽度、分段高度、分段深度、材料、侧面){
//X=长度,Y=高度,Z=深度,
THREE.FreeWallGeometry=函数(noOfSegments,segmentLength){
三、几何学。叫(这个);
变量t1,t2,
正常=新的三个向量3(0,0,1);
自由面;
var freePlane=函数(self、parametricPlane_X、parametricPlane_Y、parametricPlane_Z、等距采样器_T1、等距采样器_T2){
对于(t2=0;t2
您可以使用Firebugconsole.trace()
查看在崩溃站点之前进行了哪些调用
我不知道这是否是典型的情况,但在您的例子中,console.trace()
将向您显示调用addSelf
之前的最后一个函数调用是对computeCentroids
函数的调用,该函数在three.js
中第4939行定义
在此函数中,顶点
-数组(自定义几何体的定义在定义时用顶点填充)由面.a
、面.b
、面.c
和面.d
索引
这些索引取自几何体的面
数组(您也在自定义几何体定义中填写了该数组),可能会出现以下问题:
面由顶点组成,如果生成的顶点与生成的面的垂直索引不匹配,则某些面垂直索引可能超出顶点数组的范围。因此顶点[face.outOfBoundVerticeIndex]
将返回null而不是vertice,这会给您留下一个难以找到的bug
另外,您可能希望在v
未定义的情况下调用console.trace
,以避免用跟踪调用淹没Firefox。这可能会导致