From 51f5232a654648613d578bde9f5babb342c0c4bf Mon Sep 17 00:00:00 2001 From: Andrea Gargaro Date: Wed, 22 Nov 2023 10:01:42 +0100 Subject: [PATCH] Object3d: Add optional target to `getObjectsByProperty()`. (#27225) * getObjectsByProperty improved * Update doc * Update doc pages * Removed empty space --- docs/api/ar/core/Object3D.html | 9 ++++++--- docs/api/en/core/Object3D.html | 7 +++++-- docs/api/it/core/Object3D.html | 7 +++++-- docs/api/ko/core/Object3D.html | 7 +++++-- docs/api/zh/core/Object3D.html | 7 +++++-- src/core/Object3D.js | 14 ++++---------- 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/docs/api/ar/core/Object3D.html b/docs/api/ar/core/Object3D.html index 8b32b786cdd516..8b055b8656ee89 100644 --- a/docs/api/ar/core/Object3D.html +++ b/docs/api/ar/core/Object3D.html @@ -322,11 +322,14 @@

[method:Object3D getObjectByProperty]( [param:String name], [param:Any value معطى.

-

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value] )

+

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value], [param:Array optionalTarget] )

name -- اسم الخاصية التي يتم البحث عنها.
- value -- قيمة الخاصية المعطاة.

- + value -- قيمة الخاصية المعطاة.
+ optionalTarget -- (optional) target to set the result. + Otherwise a new Array is instantiated. If set, you must clear this + array prior to each call (i.e., array.length = 0;).

+ يبحث في كائن وأطفاله، بدءًا من الكائن نفسه، ويرجع جميع الكائنات مع خاصية تطابق القيمة معطى. diff --git a/docs/api/en/core/Object3D.html b/docs/api/en/core/Object3D.html index eb3d8503abab09..d757904e578f75 100644 --- a/docs/api/en/core/Object3D.html +++ b/docs/api/en/core/Object3D.html @@ -334,10 +334,13 @@

[method:Object3D getObjectByProperty]( [param:String name], [param:Any value given.

-

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value] )

+

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value], [param:Array optionalTarget] )

name -- the property name to search for.
- value -- value of the given property.

+ value -- value of the given property.
+ optionalTarget -- (optional) target to set the result. + Otherwise a new Array is instantiated. If set, you must clear this + array prior to each call (i.e., array.length = 0;).

Searches through an object and its children, starting with the object itself, and returns all the objects with a property that matches the value diff --git a/docs/api/it/core/Object3D.html b/docs/api/it/core/Object3D.html index d79e8063ccc6c6..1ef5e677305535 100644 --- a/docs/api/it/core/Object3D.html +++ b/docs/api/it/core/Object3D.html @@ -285,10 +285,13 @@

[method:Object3D getObjectByProperty]( [param:String name], [param:Any value Cerca in un oggetto e nei suoi figli, partendo dall'oggetto stesso, e restituisce il primo con la proprietà che corrisponde al valore passato.

-

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value] )

+

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value], [param:Array optionalTarget] )

name -- il nome della proprietà da cercare.
- value -- il valore della proprietà data.

+ value -- il valore della proprietà data.
+ optionalTarget -- (opzionale) array dove impostare il risultato. + Altrimenti viene istanziato un nuovo Array. + Se impostato, è necessario cancellare questo array prima di ogni chiamata (ad esempio, array.length = 0;).

Cerca in un oggetto e nei suoi figli, partendo dall'oggetto stesso, e restituisce tutti gli oggetti con la proprietà che corrisponde al valore passato.

diff --git a/docs/api/ko/core/Object3D.html b/docs/api/ko/core/Object3D.html index 99c9331cdaf861..d00172e3221be5 100644 --- a/docs/api/ko/core/Object3D.html +++ b/docs/api/ko/core/Object3D.html @@ -271,10 +271,13 @@

[method:Object3D getObjectByProperty]( [param:String name], [param:Any value 객체 자신부터 시작하여 객체와 객체 자식 항목을 검색하고 일치하는 값의 첫 번째 항목을 리턴합니다.

-

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value] )

+

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value], [param:Array optionalTarget] )

name -- 검색하고자하는 이름 프로퍼티.
- value -- 프로퍼티의 값.

+ value -- 프로퍼티의 값.
+ optionalTarget -- (optional) target to set the result. + Otherwise a new Array is instantiated. If set, you must clear this + array prior to each call (i.e., array.length = 0;).

개체 자체부터 시작하여 개체와 해당 자식을 검색하고 일치하는 값의 모든 개체를 반환합니다.

diff --git a/docs/api/zh/core/Object3D.html b/docs/api/zh/core/Object3D.html index 23aa484440b449..d6670fe2d35433 100644 --- a/docs/api/zh/core/Object3D.html +++ b/docs/api/zh/core/Object3D.html @@ -264,10 +264,13 @@

[method:Object3D getObjectByProperty]( [param:String name], [param:Any value 从该对象开始,搜索一个对象及其子级,返回第一个给定的属性中包含有匹配的值的子对象。

-

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value] )

+

[method:Object3D getObjectsByProperty]( [param:String name], [param:Any value], [param:Array optionalTarget] )

name —— 将要用于查找的属性的名称。
- value —— 给定的属性的值。

+ value —— 给定的属性的值。
+ optionalTarget -- (optional) target to set the result. + Otherwise a new Array is instantiated. If set, you must clear this + array prior to each call (i.e., array.length = 0;).

从此对象开始,搜索一个对象及其子对象,返回包含给定属性的匹配值的所有子对象。

diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 63736801a0edf2..33271e1e0c6f55 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -457,21 +457,15 @@ class Object3D extends EventDispatcher { } - getObjectsByProperty( name, value ) { - - let result = []; + getObjectsByProperty( name, value, result = [] ) { if ( this[ name ] === value ) result.push( this ); - for ( let i = 0, l = this.children.length; i < l; i ++ ) { - - const childResult = this.children[ i ].getObjectsByProperty( name, value ); - - if ( childResult.length > 0 ) { + const children = this.children; - result = result.concat( childResult ); + for ( let i = 0, l = children.length; i < l; i ++ ) { - } + children[ i ].getObjectsByProperty( name, value, result ); }