如何使用Vector2和Vector3代替弃用的UV和Vertex?

时间:2013-07-17 10:02:48

标签: three.js

我正在创建自定义几何体并遇到此错误: THREE.Vertex已被弃用。请改用THREE.Vector3。 THREE.UV已被弃用。请改用THREE.Vector2。

我不确定如何继续下面的代码。我该如何进行此更新?谢谢。

Saturn_RingFunct = function ( innerRadius, outerRadius, nSegments ) {
//var ringsmap = "./images/SatRing.png";
//var texture = THREE.ImageUtils.loadTexture(ringsmap);
var material = new THREE.MeshLambertMaterial( 
 { color:"yellow",wireframe:true/*map:       texture, transparent:true, ambient:0xffffff*/ } );
//var ringsMesh = new THREE.Mesh( geometry, material );

var Saturn_Rings = new THREE.Geometry();

 //THREE.Geometry.call( this );

var outerRadius = outerRadius || 1,
    innerRadius = innerRadius || .5,
    gridY = nSegments || 10;

var i, twopi = 2 * Math.PI;
var iVer = Math.max( 2, gridY );

var origin = new THREE.Vector3(0, 0, 0);
//this.vertices.push(new THREE.Vertex(origin));

for ( i = 0; i < ( iVer + 1 ) ; i++ ) {

var fRad1 = i / iVer;
var fRad2 = (i + 1) / iVer;
var fX1 = innerRadius * Math.cos( fRad1 * twopi );
var fY1 = innerRadius * Math.sin( fRad1 * twopi );
var fX2 = outerRadius * Math.cos( fRad1 * twopi );
var fY2 = outerRadius * Math.sin( fRad1 * twopi );
var fX4 = innerRadius * Math.cos( fRad2 * twopi );
var fY4 = innerRadius * Math.sin( fRad2 * twopi );
var fX3 = outerRadius * Math.cos( fRad2 * twopi );
var fY3 = outerRadius * Math.sin( fRad2 * twopi );

var v1 = new THREE.Vector3( fX1, fY1, 0 );
var v2 = new THREE.Vector3( fX2, fY2, 0 );
var v3 = new THREE.Vector3( fX3, fY3, 0 );
var v4 = new THREE.Vector3( fX4, fY4, 0 );
Saturn_Rings.vertices.push( new THREE.Vertex( v1 ) );
Saturn_Rings.vertices.push( new THREE.Vertex( v2 ) );
Saturn_Rings.vertices.push( new THREE.Vertex( v3 ) );
Saturn_Rings.vertices.push( new THREE.Vertex( v4 ) );

}

for ( i = 0; i < iVer ; i++ ) {

Saturn_Rings.faces.push(new THREE.Face3( i * 4, i * 4 + 1, i * 4 + 2));
Saturn_Rings.faces.push(new THREE.Face3( i * 4, i * 4 + 2, i * 4 + 3));
Saturn_Rings.faceVertexUvs[ 0 ].push( [
    new THREE.UV(0, 1),
    new THREE.UV(1, 1),
    new THREE.UV(1, 0) ] );
Saturn_Rings.faceVertexUvs[ 0 ].push( [
    new THREE.UV(0, 1),
    new THREE.UV(1, 0),
    new THREE.UV(0, 0) ] );
}

Saturn_Rings.computeCentroids();
Saturn_Rings.computeFaceNormals();
Saturn_Rings.computeVertexNormals();
//Saturn_Rings.boundingSphere = { radius: outerRadius };
var object = new THREE.Mesh(Saturn_Rings, material);
object.doubleSided = true;
object.doubleSided = true;
object.rotation.x = Math.PI / 2;
scene.add(object);
 }

1 个答案:

答案 0 :(得分:3)

这意味着您现在可以直接在以前需要使用Vertex和UV的位置使用Vector3和Vector2对象。

而不是:

Saturn_Rings.faceVertexUvs[ 0 ].push( [
    new THREE.UV(0, 1),
    new THREE.UV(1, 1),
   new THREE.UV(1, 0) ] );

你可以这样做:

Saturn_Rings.faceVertexUvs[ 0 ].push( [
    new THREE.Vector2(0, 1),
    new THREE.Vector2(1, 1),
   new THREE.Vector2(1, 0) ] );

而不是:

var v1 = new THREE.Vector3( fX1, fY1, 0 );
Saturn_Rings.vertices.push( new THREE.Vertex( v1 ) );

你可以这样做:

var v1 = new THREE.Vector3( fX1, fY1, 0 );
Saturn_Rings.vertices.push(v1);

等等。