How to create large meshes with immediate geometry?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gharms
:warning: Old Version Published before Godot 3 was released.

I am using Godot to import a model from an .STL file in order to write a user interface for a robotic arm power washer. I have successfully displayed models with less than 1024 facets, but when they get larger, the facets with an index greater than 1024 show as transparent.

Below I show the function used to build the mesh from an array of facets. This is inside of a MeshInstance node. This node’s parent is a RigidBody who’s addShapes() function creates a trimesh shape and adds it to the RigidBody. I am then able to perform collisions, even with the facets that are transparent.

func setTriangles(newTriangles):
	surfTool =
	var mesh =
	var dataTool =
	var material =
	var selectedTriangles = []
	material.set_fixed_flag(FixedMaterial.FLAG_USE_COLOR_ARRAY, true)
	for triangle in triangles:
		changeColor(triangle, selectedTriangles)

I also have an additional procedurally generated line (primitive_line_strip) using immediate geometry in an ImmediateGeometry node which shows the path of the arm. This is built after the part model, and also does not appear if the part model size is greater than 1024 facets.

I am not aware of any maximum number for immediate geometry shapes, but it looks like I am running into a wall somehow. Anyone have any ideas?

:bust_in_silhouette: Reply From: mollusca

It looks like you’re creating a new surface for every triangle. I guess a Meshcan only have 1024 surfaces? Try moving surfTool.begin(), surfTool.index() and surfTool.commit() outside the loop, so that you’re only creating one surface from the set of triangles.

That worked! Thank you!

gharms | 2018-01-17 17:55