I am using the threejs library in haxe, and I encountered a type detection problem when practicing the official case code:
object.traverse(function (child) {
if ((child as THREE.Mesh).isMesh) {
// do something
}
})
where in haxe THREE.Mesh is defined as
extern class Mesh<TGeometry, TMaterial> extends Object3D<Event>
I’cant just call(cast child: Mesh).isMesh
, there will be “no enough parameters” error, what should i do?
FlowSand
(Xuzx)
July 29, 2022, 11:12am
2
Looks like I’m not skilled enough in web development and Haxe,After trying it out, I found that I can use the console to see the loaded stack of model objects and see their concrete types,and then,i can write like:
(cast child : SkinnedMesh(BufferGeometry, MeshPhongMaterial))
,
On the other hand, it looks like this question is asking a bit odd
FlowSand
(Xuzx)
July 29, 2022, 11:12am
3
Since Haxe 4.0.0 some new features have been added, it is also possible to write:
var isMesh = js.Syntax.code("child.isMesh");
Although it is not suitable for some scenarios, I don’t know if there is a better way for this case.
can you share the part of your haxe code where this casting occurs or where you’re checking against isMesh?
Ok, I just rewriting the official Threejs case code in Haxe, which was written in js, and encountered a type conversion detection:
(child as THREE.Mesh).isMesh
At first I wanted to write like this in haxe
(cast child: THREE.Mesh).isMesh
But this doesn’t work, Mesh is generic type and needs to receive two parameters
Later I tried using the above two methods,And after the haxiomic prompt, you can also write like this:
child is three.Mesh
or
(cast child: Mesh<Any, Any>)
Shouldn’t be enough to write untyped child.isMesh
?