Преглед изворни кода

BufferGeometry: Add hasAttribute().

Mugen87 пре 4 година
родитељ
комит
91b8e6be0c

+ 3 - 0
docs/api/en/core/BufferGeometry.html

@@ -233,6 +233,9 @@
 		<h3>[method:BufferAttribute getIndex] ()</h3>
 		<p>Return the [page:.index] buffer.</p>
 
+		<h3>[method:Boolean hasAttribute]( [param:String name] )</h3>
+		<p>Returns *true* if the attribute with the specified name exists.</p>
+
 		<h3>[method:BufferGeometry lookAt] ( [param:Vector3 vector] )</h3>
 		<p>
 		vector - A world vector to look at.<br /><br />

+ 3 - 0
docs/api/zh/core/BufferGeometry.html

@@ -222,6 +222,9 @@
 		<h3>[method:BufferAttribute getIndex] ()</h3>
 		<p>返回缓存相关的 [page:.index]。</p>
 
+		<h3>[method:Boolean hasAttribute]( [param:String name] )</h3>
+		<p>Returns *true* if the attribute with the specified name exists.</p>
+
 		<h3>[method:BufferGeometry lookAt] ( [param:Vector3 vector] )</h3>
 		<p>
 			vector - 几何体所朝向的世界坐标。<br /><br />

+ 2 - 2
editor/js/Loader.js

@@ -201,7 +201,7 @@ function Loader( editor ) {
 
 							var material = new THREE.PointsMaterial( { size: 0.01 } );
 
-							if ( geometry.getAttribute( 'color' ) !== undefined ) material.vertexColors = true;
+							if ( geometry.hasAttribute( 'color' ) === true ) material.vertexColors = true;
 
 							object = new THREE.Points( geometry, material );
 							object.name = filename;
@@ -556,7 +556,7 @@ function Loader( editor ) {
 
 					var material = new THREE.PointsMaterial();
 
-					if ( geometry.getAttribute( 'color' ) !== undefined ) material.vertexColors = true;
+					if ( geometry.hasAttribute( 'color' ) === true ) material.vertexColors = true;
 
 					var points = new THREE.Points( geometry, material );
 					points.name = filename;

+ 1 - 1
examples/js/exporters/PLYExporter.js

@@ -45,7 +45,7 @@ THREE.PLYExporter.prototype = {
 
 					if ( geometry.isBufferGeometry === true ) {
 
-						if ( geometry.getAttribute( 'position' ) !== undefined ) {
+						if ( geometry.hasAttribute( 'position' ) === true ) {
 
 							cb( mesh, geometry );
 

+ 1 - 0
src/core/BufferGeometry.d.ts

@@ -98,6 +98,7 @@ export class BufferGeometry extends EventDispatcher {
 	setAttribute( name: string, attribute: BufferAttribute | InterleavedBufferAttribute ): BufferGeometry;
 	getAttribute( name: string ): BufferAttribute | InterleavedBufferAttribute;
 	deleteAttribute( name: string ): BufferGeometry;
+	hasAttribute( name: string ): boolean;
 
 	addGroup( start: number, count: number, materialIndex?: number ): void;
 	clearGroups(): void;

+ 6 - 0
src/core/BufferGeometry.js

@@ -95,6 +95,12 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 	},
 
+	hasAttribute: function ( name ) {
+
+		return this.attributes[ name ] !== undefined;
+
+	},
+
 	addGroup: function ( start, count, materialIndex ) {
 
 		this.groups.push( {

+ 2 - 2
src/renderers/webgl/WebGLMorphtargets.js

@@ -111,13 +111,13 @@ function WebGLMorphtargets( gl ) {
 
 			} else {
 
-				if ( morphTargets && geometry.getAttribute( 'morphTarget' + i ) !== undefined ) {
+				if ( morphTargets && geometry.hasAttribute( 'morphTarget' + i ) === true ) {
 
 					geometry.deleteAttribute( 'morphTarget' + i );
 
 				}
 
-				if ( morphNormals && geometry.getAttribute( 'morphNormal' + i ) !== undefined ) {
+				if ( morphNormals && geometry.hasAttribute( 'morphNormal' + i ) === true ) {
 
 					geometry.deleteAttribute( 'morphNormal' + i );