未验证 提交 c687a368 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #21026 from Mugen87/dev2

Decal/Edges/WireframeGeometry: Stop Geometry support.
......@@ -29,7 +29,7 @@ scene.add( line );
<h2>Constructor</h2>
<h3>[name]( [param:Geometry geometry], [param:Integer thresholdAngle] )</h3>
<h3>[name]( [param:BufferGeometry geometry], [param:Integer thresholdAngle] )</h3>
<p>
geometry — Any geometry object.<br />
thresholdAngle — An edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
......
......@@ -36,7 +36,7 @@
<h2>Constructor</h2>
<h3>[name]( [param:Geometry geometry] )</h3>
<h3>[name]( [param:BufferGeometry geometry] )</h3>
<p>
geometry — any geometry object.
</p>
......
......@@ -28,7 +28,7 @@
<h2>构造器</h2>
<h3>[name]( [param:Geometry geometry], [param:Integer thresholdAngle] )</h3>
<h3>[name]( [param:BufferGeometry geometry], [param:Integer thresholdAngle] )</h3>
<p>
geometry — 任何一个几何体对象。<br />
thresholdAngle — 仅当相邻面的法线之间的角度(单位为角度)超过这个值时,才会渲染边缘。默认值为1。
......
......@@ -35,7 +35,7 @@
<h2>构造器</h2>
<h3>[name]( [param:Geometry geometry] )</h3>
<h3>[name]( [param:BufferGeometry geometry] )</h3>
<p>
geometry — 任意几何体对象。
</p>
......
......@@ -49,7 +49,7 @@ THREE.DecalGeometry = function ( mesh, position, orientation, size ) {
function generate() {
var i;
var geometry = new THREE.BufferGeometry();
var decalVertices = [];
var vertex = new THREE.Vector3();
......@@ -57,16 +57,15 @@ THREE.DecalGeometry = function ( mesh, position, orientation, size ) {
// handle different geometry types
if ( mesh.geometry.isGeometry ) {
geometry.fromGeometry( mesh.geometry );
if ( mesh.geometry.isGeometry === true ) {
} else {
geometry.copy( mesh.geometry );
console.error( 'THREE.DecalGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
return;
}
var geometry = mesh.geometry;
var positionAttribute = geometry.attributes.position;
var normalAttribute = geometry.attributes.normal;
......
......@@ -56,7 +56,7 @@ var DecalGeometry = function ( mesh, position, orientation, size ) {
function generate() {
var i;
var geometry = new BufferGeometry();
var decalVertices = [];
var vertex = new Vector3();
......@@ -64,16 +64,15 @@ var DecalGeometry = function ( mesh, position, orientation, size ) {
// handle different geometry types
if ( mesh.geometry.isGeometry ) {
geometry.fromGeometry( mesh.geometry );
if ( mesh.geometry.isGeometry === true ) {
} else {
geometry.copy( mesh.geometry );
console.error( 'THREE.DecalGeometry no longer supports THREE.Geometry. Use BufferGeometry instead.' );
return;
}
var geometry = mesh.geometry;
var positionAttribute = geometry.attributes.position;
var normalAttribute = geometry.attributes.normal;
......
import { BufferGeometry } from '../core/BufferGeometry';
import { Geometry } from '../core/Geometry';
export class EdgesGeometry extends BufferGeometry {
......@@ -7,7 +6,7 @@ export class EdgesGeometry extends BufferGeometry {
* @param geometry
* @param [thresholdAngle=1]
*/
constructor( geometry: BufferGeometry | Geometry, thresholdAngle?: number );
constructor( geometry: BufferGeometry, thresholdAngle?: number );
/**
* @default 'EdgesGeometry'
......
......@@ -23,9 +23,10 @@ class EdgesGeometry extends BufferGeometry {
thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
if ( geometry.isGeometry ) {
if ( geometry.isGeometry === true ) {
geometry = new BufferGeometry().fromGeometry( geometry );
console.error( 'THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
return;
}
......
import { Geometry } from './../core/Geometry';
import { BufferGeometry } from './../core/BufferGeometry';
export class WireframeGeometry extends BufferGeometry {
constructor( geometry: Geometry | BufferGeometry );
constructor( geometry: BufferGeometry );
/**
* @default 'WireframeGeometry'
......
......@@ -9,6 +9,13 @@ class WireframeGeometry extends BufferGeometry {
super();
this.type = 'WireframeGeometry';
if ( geometry.isGeometry === true ) {
console.error( 'THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
return;
}
// buffer
const vertices = [];
......@@ -16,96 +23,46 @@ class WireframeGeometry extends BufferGeometry {
// helper variables
const edge = [ 0, 0 ], edges = {};
const keys = [ 'a', 'b', 'c' ];
// different logic for Geometry and BufferGeometry
if ( geometry && geometry.isGeometry ) {
// create a data structure that contains all edges without duplicates
const faces = geometry.faces;
for ( let i = 0, l = faces.length; i < l; i ++ ) {
const face = faces[ i ];
for ( let j = 0; j < 3; j ++ ) {
const edge1 = face[ keys[ j ] ];
const edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
edge[ 1 ] = Math.max( edge1, edge2 );
const key = edge[ 0 ] + ',' + edge[ 1 ];
const vertex = new Vector3();
if ( edges[ key ] === undefined ) {
if ( geometry.index !== null ) {
edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
// indexed BufferGeometry
}
}
const position = geometry.attributes.position;
const indices = geometry.index;
let groups = geometry.groups;
}
if ( groups.length === 0 ) {
// generate vertices
for ( const key in edges ) {
const e = edges[ key ];
let vertex = geometry.vertices[ e.index1 ];
vertices.push( vertex.x, vertex.y, vertex.z );
vertex = geometry.vertices[ e.index2 ];
vertices.push( vertex.x, vertex.y, vertex.z );
groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
}
} else if ( geometry && geometry.isBufferGeometry ) {
// create a data structure that contains all eges without duplicates
const vertex = new Vector3();
for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
if ( geometry.index !== null ) {
const group = groups[ o ];
// indexed BufferGeometry
const start = group.start;
const count = group.count;
const position = geometry.attributes.position;
const indices = geometry.index;
let groups = geometry.groups;
for ( let i = start, l = ( start + count ); i < l; i += 3 ) {
if ( groups.length === 0 ) {
groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
}
// create a data structure that contains all eges without duplicates
for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
const group = groups[ o ];
const start = group.start;
const count = group.count;
for ( let i = start, l = ( start + count ); i < l; i += 3 ) {
for ( let j = 0; j < 3; j ++ ) {
const edge1 = indices.getX( i + j );
const edge2 = indices.getX( i + ( j + 1 ) % 3 );
edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
edge[ 1 ] = Math.max( edge1, edge2 );
for ( let j = 0; j < 3; j ++ ) {
const key = edge[ 0 ] + ',' + edge[ 1 ];
const edge1 = indices.getX( i + j );
const edge2 = indices.getX( i + ( j + 1 ) % 3 );
edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
edge[ 1 ] = Math.max( edge1, edge2 );
if ( edges[ key ] === undefined ) {
const key = edge[ 0 ] + ',' + edge[ 1 ];
edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
if ( edges[ key ] === undefined ) {
}
edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
}
......@@ -113,42 +70,42 @@ class WireframeGeometry extends BufferGeometry {
}
// generate vertices
}
for ( const key in edges ) {
// generate vertices
const e = edges[ key ];
for ( const key in edges ) {
vertex.fromBufferAttribute( position, e.index1 );
vertices.push( vertex.x, vertex.y, vertex.z );
const e = edges[ key ];
vertex.fromBufferAttribute( position, e.index2 );
vertices.push( vertex.x, vertex.y, vertex.z );
vertex.fromBufferAttribute( position, e.index1 );
vertices.push( vertex.x, vertex.y, vertex.z );
}
vertex.fromBufferAttribute( position, e.index2 );
vertices.push( vertex.x, vertex.y, vertex.z );
} else {
}
// non-indexed BufferGeometry
} else {
const position = geometry.attributes.position;
// non-indexed BufferGeometry
for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
const position = geometry.attributes.position;
for ( let j = 0; j < 3; j ++ ) {
for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
// three edges per triangle, an edge is represented as (index1, index2)
// e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
for ( let j = 0; j < 3; j ++ ) {
const index1 = 3 * i + j;
vertex.fromBufferAttribute( position, index1 );
vertices.push( vertex.x, vertex.y, vertex.z );
// three edges per triangle, an edge is represented as (index1, index2)
// e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
const index2 = 3 * i + ( ( j + 1 ) % 3 );
vertex.fromBufferAttribute( position, index2 );
vertices.push( vertex.x, vertex.y, vertex.z );
const index1 = 3 * i + j;
vertex.fromBufferAttribute( position, index1 );
vertices.push( vertex.x, vertex.y, vertex.z );
}
const index2 = 3 * i + ( ( j + 1 ) % 3 );
vertex.fromBufferAttribute( position, index2 );
vertices.push( vertex.x, vertex.y, vertex.z );
}
......
/* global QUnit */
import { EdgesGeometry } from '../../../../src/geometries/EdgesGeometry';
import { Geometry } from '../../../../src/core/Geometry';
import { BufferGeometry } from '../../../../src/core/BufferGeometry';
import { BufferAttribute } from '../../../../src/core/BufferAttribute';
import { Vector3 } from '../../../../src/math/Vector3';
......@@ -41,10 +40,8 @@ function testEdges( vertList, idxList, numAfter, assert ) {
function createGeometries( vertList, idxList ) {
var geomIB = createIndexedBufferGeometry( vertList, idxList );
var geom = new Geometry().fromBufferGeometry( geomIB );
var geomB = new BufferGeometry().fromGeometry( geom );
var geomDC = addDrawCalls( geomIB.clone() );
return [ geom, geomB, geomIB, geomDC ];
return [ geomIB, geomDC ];
}
......
......@@ -44,7 +44,7 @@ var files = [
{ path: 'geometries/BoxLineGeometry.js', dependencies: [], ignoreList: [] },
{ path: 'geometries/ConvexGeometry.js', dependencies: [ { name: 'ConvexHull', path: 'math/ConvexHull.js' } ], ignoreList: [] },
{ path: 'geometries/DecalGeometry.js', dependencies: [], ignoreList: [] },
{ path: 'geometries/DecalGeometry.js', dependencies: [], ignoreList: [ 'Geometry' ] },
{ path: 'geometries/LightningStrike.js', dependencies: [ { name: 'SimplexNoise', path: 'math/SimplexNoise.js' } ], ignoreList: [ 'Mesh' ] },
{ path: 'geometries/ParametricGeometries.js', dependencies: [], ignoreList: [] },
{ path: 'geometries/TeapotBufferGeometry.js', dependencies: [], ignoreList: [] },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册