2
0
Эх сурвалжийг харах

Examples: More Geometry removal.

Mugen87 4 жил өмнө
parent
commit
2aa13314aa

BIN
examples/screenshots/webgl_geometry_text.jpg


+ 20 - 7
examples/webgl_geometry_convex.html

@@ -16,6 +16,7 @@
 
 			import { OrbitControls } from './jsm/controls/OrbitControls.js';
 			import { ConvexBufferGeometry } from './jsm/geometries/ConvexGeometry.js';
+			import { BufferGeometryUtils } from './jsm/utils/BufferGeometryUtils.js';
 
 			let group, camera, scene, renderer;
 
@@ -43,13 +44,13 @@
 				controls.minDistance = 20;
 				controls.maxDistance = 50;
 				controls.maxPolarAngle = Math.PI / 2;
-				
+
 				// ambient light
-				
+
 				scene.add( new THREE.AmbientLight( 0x222222 ) );
-				
+
 				// point light
-				
+
 				const light = new THREE.PointLight( 0xffffff, 1 );
 				camera.add( light );
 
@@ -67,11 +68,23 @@
 
 				// points
 
-				const vertices = new THREE.DodecahedronGeometry( 10 ).vertices;
+				let dodecahedronGeometry = new THREE.DodecahedronBufferGeometry( 10 );
+
+				// if normal and uv attributes are not removed, mergeVertices() can't consolidate indentical vertices with different normal/uv data
+
+				dodecahedronGeometry.deleteAttribute( 'normal' );
+				dodecahedronGeometry.deleteAttribute( 'uv' );
+
+				dodecahedronGeometry = BufferGeometryUtils.mergeVertices( dodecahedronGeometry );
+
+				const vertices = [];
+				const positionAttribute = dodecahedronGeometry.getAttribute( 'position' );
 
-				for ( let i = 0; i < vertices.length; i ++ ) {
+				for ( let i = 0; i < positionAttribute.count; i ++ ) {
 
-					//vertices[ i ].add( randomPoint().multiplyScalar( 2 ) ); // wiggle the points
+					const vertex = new THREE.Vector3();
+					vertex.fromBufferAttribute( positionAttribute, i );
+					vertices.push( vertex );
 
 				}
 

+ 1 - 48
examples/webgl_geometry_text.html

@@ -339,7 +339,7 @@
 
 			function createText() {
 
-				textGeo = new THREE.TextGeometry( text, {
+				textGeo = new THREE.TextBufferGeometry( text, {
 
 					font: font,
 
@@ -354,56 +354,9 @@
 				} );
 
 				textGeo.computeBoundingBox();
-				textGeo.computeVertexNormals();
-
-				const triangle = new THREE.Triangle();
-
-				// "fix" side normals by removing z-component of normals for side faces
-				// (this doesn't work well for beveled geometry as then we lose nice curvature around z-axis)
-
-				if ( ! bevelEnabled ) {
-
-					const triangleAreaHeuristics = 0.1 * ( height * size );
-
-					for ( let i = 0; i < textGeo.faces.length; i ++ ) {
-
-						const face = textGeo.faces[ i ];
-
-						if ( face.materialIndex == 1 ) {
-
-							for ( let j = 0; j < face.vertexNormals.length; j ++ ) {
-
-								face.vertexNormals[ j ].z = 0;
-								face.vertexNormals[ j ].normalize();
-
-							}
-
-							const va = textGeo.vertices[ face.a ];
-							const vb = textGeo.vertices[ face.b ];
-							const vc = textGeo.vertices[ face.c ];
-
-							const s = triangle.set( va, vb, vc ).getArea();
-
-							if ( s > triangleAreaHeuristics ) {
-
-								for ( let j = 0; j < face.vertexNormals.length; j ++ ) {
-
-									face.vertexNormals[ j ].copy( face.normal );
-
-								}
-
-							}
-
-						}
-
-					}
-
-				}
 
 				const centerOffset = - 0.5 * ( textGeo.boundingBox.max.x - textGeo.boundingBox.min.x );
 
-				textGeo = new THREE.BufferGeometry().fromGeometry( textGeo );
-
 				textMesh1 = new THREE.Mesh( textGeo, materials );
 
 				textMesh1.position.x = centerOffset;

+ 2 - 2
test/unit/src/animation/PropertyBinding.tests.js

@@ -1,7 +1,7 @@
 /* global QUnit */
 
 import { PropertyBinding } from '../../../../src/animation/PropertyBinding';
-import { BoxGeometry } from '../../../../src/geometries/BoxGeometry';
+import { BoxBufferGeometry } from '../../../../src/geometries/BoxGeometry';
 import { Mesh } from '../../../../src/objects/Mesh';
 import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial';
 
@@ -331,7 +331,7 @@ export default QUnit.module( 'Animation', () => {
 				var originalValue = 0;
 				var expectedValue = 1;
 
-				var geometry = new BoxGeometry();
+				var geometry = new BoxBufferGeometry();
 				var material = new MeshBasicMaterial();
 				material.opacity = originalValue;
 				var mesh = new Mesh( geometry, material );

+ 4 - 4
test/unit/src/helpers/BoxHelper.tests.js

@@ -2,8 +2,8 @@
 
 import { runStdGeometryTests } from '../../utils/qunit-utils';
 import { BoxHelper } from '../../../../src/helpers/BoxHelper';
-import { BoxGeometry } from '../../../../src/geometries/BoxGeometry';
-import { SphereGeometry } from '../../../../src/geometries/SphereGeometry';
+import { BoxBufferGeometry } from '../../../../src/geometries/BoxBufferGeometry';
+import { SphereBufferGeometry } from '../../../../src/geometries/SphereBufferGeometry';
 import { Mesh } from '../../../../src/objects/Mesh';
 
 export default QUnit.module( 'Helpers', () => {
@@ -14,12 +14,12 @@ export default QUnit.module( 'Helpers', () => {
 		hooks.beforeEach( function () {
 
 			// Test with a normal cube and a box helper
-			var boxGeometry = new BoxGeometry();
+			var boxGeometry = new BoxBufferGeometry();
 			var box = new Mesh( boxGeometry );
 			var boxHelper = new BoxHelper( box );
 
 			// The same should happen with a comparable sphere
-			var sphereGeometry = new SphereGeometry();
+			var sphereGeometry = new SphereBufferGeometry();
 			var sphere = new Mesh( sphereGeometry );
 			var sphereBoxHelper = new BoxHelper( sphere );
 

+ 3 - 4
test/unit/src/math/Box3.tests.js

@@ -8,7 +8,6 @@ import { Vector3 } from '../../../../src/math/Vector3';
 import { Matrix4 } from '../../../../src/math/Matrix4';
 import { Mesh } from '../../../../src/objects/Mesh';
 import { BufferAttribute } from '../../../../src/core/BufferAttribute';
-import { BoxGeometry } from '../../../../src/geometries/BoxGeometry';
 import { BoxBufferGeometry } from '../../../../src/geometries/BoxBufferGeometry';
 import {
 	negInf3,
@@ -305,9 +304,9 @@ export default QUnit.module( 'Maths', () => {
 
 			var a = new Box3( zero3.clone(), one3.clone() );
 			var b = a.clone();
-			var bigger = new Mesh( new BoxGeometry( 2, 2, 2 ) );
-			var smaller = new Mesh( new BoxGeometry( 0.5, 0.5, 0.5 ) );
-			var child = new Mesh( new BoxGeometry( 1, 1, 1 ) );
+			var bigger = new Mesh( new BoxBufferGeometry( 2, 2, 2 ) );
+			var smaller = new Mesh( new BoxBufferGeometry( 0.5, 0.5, 0.5 ) );
+			var child = new Mesh( new BoxBufferGeometry( 1, 1, 1 ) );
 
 			// just a bigger box to begin with
 			a.expandByObject( bigger );

+ 2 - 2
test/unit/src/math/Frustum.tests.js

@@ -8,7 +8,7 @@ import { Vector3 } from '../../../../src/math/Vector3';
 import { Matrix4 } from '../../../../src/math/Matrix4';
 import { Box3 } from '../../../../src/math/Box3';
 import { Mesh } from '../../../../src/objects/Mesh';
-import { BoxGeometry } from '../../../../src/geometries/BoxGeometry';
+import { BoxBufferGeometry } from '../../../../src/geometries/BoxBufferGeometry';
 import { zero3, one3, eps } from './Constants.tests';
 
 const unit3 = new Vector3( 1, 0, 0 );
@@ -204,7 +204,7 @@ export default QUnit.module( 'Maths', () => {
 
 			var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
 			var a = new Frustum().setFromProjectionMatrix( m );
-			var object = new Mesh( new BoxGeometry( 1, 1, 1 ) );
+			var object = new Mesh( new BoxBufferGeometry( 1, 1, 1 ) );
 			var intersects;
 
 			intersects = a.intersectsObject( object );