How to query objects that bypass the scene system
The instances_cull_ray function cannot query the object.
What are you trying to do and what did you draw? Can you explain a bit more, because it is hard to answer your question without more information.
var arr = new object[(int)Mesh.ArrayType.Max];
Vector3[] vertexs = new Vector3[]{
new Vector3(-1, -1, 0),
new Vector3(1, -1, 0),
new Vector3(1, 1, 0)
};
int[] index = new int[]{
0, 1, 2
};
arr[(int)Mesh.ArrayType.Vertex] = vertexs;
arr[(int)Mesh.ArrayType.Index] = index;
var meshrid = VisualServer.MeshCreate();
VisualServer.MeshAddSurfaceFromArrays(meshrid, VisualServer.PrimitiveType.Triangles, new Godot.Collections.Array(arr));
var ins = VisualServer.InstanceCreate2(meshrid, GetWorld().Scenario);
SpatialMaterial mtl = new SpatialMaterial();
mtl.ParamsCullMode = SpatialMaterial.CullMode.Disabled;
mtl.AlbedoColor = new Color(1, 0, 0);
VisualServer.InstanceSetSurfaceMaterial(ins, 0, mtl.GetRid());
I mean, after using the above sample code to draw a mesh(for some reason I don't want to use meshinstance for drawing), I can't use the instances_cull_ray function to query the mesh that I just drew. Is there any other interface that can easily implement the function of click query?
ning_xue " I can't use the instances_cull_ray function to query the mesh that I just drew"
Why can't you use instances_cull_ray()? Did you actually draw the mesh, or just create it? If I'm reading the docs correctly, then to use the VisualServer, the object must be drawn to a viewport, so if you create a mesh, but don't add it to a scene, then you can't query, b/c it's not drawn.
- Edited
The geometry class has math functions you can use in pure code.
https://docs.godotengine.org/en/stable/classes/class_geometry.html