tres
tres copied to clipboard
Allow `TresObject3D#material` to set Array
Description
Currently, TresObject3D#material
doesn't allow to set array. My suggestion is to make Array acceptable as well.
https://github.com/Tresjs/tres/blob/main/src/types/index.ts#L43
- material?: THREE.Material & TresBaseObject
+ material?: THREE.Material & TresBaseObject | (THREE.Material & TresBaseObject)[]
(Personal) reason
I use TresJS and spine-ts THREE.JS.
THREE.Mesh#material's type is Material | Material[]
. (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/three/src/objects/Mesh.d.ts#L24)
spine-ts' set Array material according to THREE's type. (https://github.com/EsotericSoftware/spine-runtimes/blob/4.1/spine-ts/spine-threejs/src/MeshBatcher.ts#L60)
However, TresObject3D#material
doesn't allow to set Array material, when a spine's mesh is rendered in Scene of TresJS and a materials in spine's mesh are evaluate, TresJS throws runtime error.
Basis that my suggestion is reasonable
A type of THREE.Mesh#material extending THREE.Object3D is Material | Material[]
, so I think it's reasonable that a type of TresObject3D#material
extending THREE.Object3D is THREE.Material & TresBaseObject | (THREE.Material & TresBaseObject)[]
.
Suggested solution
https://github.com/Tresjs/tres/blob/main/src/types/index.ts#L43
- material?: THREE.Material & TresBaseObject
+ material?: THREE.Material & TresBaseObject | (THREE.Material & TresBaseObject)[]
and adding logic for array.
Alternative
nothing. I currently use pnpm patch and add logic for array.
Additional context
I can create PR for this suggestion.
Validations
- [X] I agree to follow this project's Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.