Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufferGeometry: Add hasAttribute(). #20733

Merged
merged 1 commit into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api/en/core/BufferGeometry.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ <h3>[method:BufferAttribute getAttribute]( [param:String name] )</h3>
<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 />
Expand Down
3 changes: 3 additions & 0 deletions docs/api/zh/core/BufferGeometry.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ <h3>[method:BufferAttribute getAttribute]( [param:String name] )</h3>
<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 />
Expand Down
4 changes: 2 additions & 2 deletions editor/js/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/js/exporters/PLYExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ THREE.PLYExporter.prototype = {

if ( geometry.isBufferGeometry === true ) {

if ( geometry.getAttribute( 'position' ) !== undefined ) {
if ( geometry.hasAttribute( 'position' ) === true ) {

cb( mesh, geometry );

Expand Down
1 change: 1 addition & 0 deletions src/core/BufferGeometry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl/WebGLMorphtargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down