I have been researching for a while and can not find an answer to this.
I would like to generate a mesh from a collection of XYZ data points saved in a text document. From there, I would like to have physics applied to the mesh and have an interactive character (capsule for now) that falls on the mesh and tumbles. The only issue I am running into is that the mesh I have generated does not have a collision. I have tried so many different methods online to generate a collision object, but it either comes up as NULL or says it works, but the capsule passes straight through.
I would like to do all of this in GDScript if possible. What do I have wrong?
Thanks
Frank
func _generateMesh():
var meshInst = MeshInstance3D.new()
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
#adding vertices, uvs and stuff to SurfaceTool
var a_mesh:ArrayMesh
var surftool = SurfaceTool.new()
#var surftool = MeshInstance3D.new()
var mesh_arr = []
mesh_arr.resize(Mesh.ARRAY_MAX)
var mesh_normals = PackedVector3Array()
var mesh_verticies = PackedVector3Array()
var mesh_indices = PackedInt64Array()
var uvs = PackedVector2Array()
var pnt = PackedVector3Array()
var MakeSurf = true
var MakePoints = false
surftool.begin(Mesh.PRIMITIVE_TRIANGLES)
var f = FileAccess.open(text_file, FileAccess.READ)
var index = 0
while not f.eof_reached():
var line = f.get_line()
if index >0:
var x = line.get_slice("\t",0)
var z = line.get_slice("\t",1)
var y = line.get_slice("\t",2)
x = x.replace(" ","")
y = y.replace(" ","")
z = z.replace(" ","")
var vx = (float(x) - CenterX) * ScaleX
var vy = (float(y) - CenterY) * ScaleY
var vz = (float(z) - CenterZ) * ScaleZ
mesh_verticies.append(Vector3(vz, vy, vx))
mesh_normals.append(Vector3(0,-1,0))
index += 1
f.close
if MakePoints:
for i in mesh_verticies:
draw_sphere(i)
if MakeSurf:
for i in mesh_verticies:
surftool.add_vertex(i)
if MakeSurf:
for xp in xSize-1:
for zp in zSize-1:
var n = int(zp+(zSize*xp))
#this is gor graphing top side
#
surftool.add_index(n)
surftool.add_index(n+1)
surftool.add_index(n+zSize)
surftool.add_index(n+zSize)
surftool.add_index(n+1)
surftool.add_index(n+zSize+1)
surftool.generate_normals()
meshInst = surftool.commit()
var mat = StandardMaterial3D.new()
var tex = load("res://aerial_grass_rock_4k.blend/textures/aerial_grass_rock_diff_4k.jpg")
var roug = load("res://aerial_grass_rock_4k.blend/textures/aerial_grass_rock_rough_4k.jpg")
mat.albedo_texture = tex
mat.roughness_texture = roug
mat.roughness_texture_channel = BaseMaterial3D.TEXTURE_CHANNEL_ALPHA
mat.roughness = 0.5
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
mat.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_ALWAYS
mat.diffuse_mode = BaseMaterial3D.DIFFUSE_LAMBERT_WRAP
mat.specular_mode = BaseMaterial3D.SPECULAR_DISABLED
mat.rim_enabled = true
mat.albedo_texture_force_srgb = true
#mat.shading_mode = BaseMaterial3D.SHADING_MODE_MAX
mat.uv1_scale = Vector3(0.01,0.01,0.01)
mat.uv1_triplanar = true
meshInst.surface_set_material(0,mat)
mesh = meshInst
mesh.shape = mesh.create_trimesh_shape()