Notifications
Clear all

[Closed] custom mesh trouble

I’m trying to create a mesh from the data attached:
(save it to a text file and point to it in the script).

stigatle.net/uploads/custom_mesh.zip


datafile = openFile "C:\\mesh.txt" mode:"r"
	vert_array = #()
	face_array = #()
	vert_count = 0
	
	while (eof datafile !=true)do
	(
		
		tempArr = #()
		templine = readline datafile
		
		tempsplitstring = filterString templine ","
		append tempArr tempsplitstring
		point_1 = tempsplitstring[1] as float
		point_2 = tempsplitstring[2] as float
		point_3 = tempsplitstring[3] as float
		append vert_array [point_1,point_2,point_3]
		face1=vert_count+1 as integer
		face2=vert_count+2 as integer
		face3=vert_count+3 as integer
		append face_array [face1,face3,face2]
		
		vert_count += 3
	)
	m = mesh vertices:vert_array faces:face_array
	

I keep running into this problem:


-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2012\Scripts\custommes.ms; position: 649; line: 25
-- Runtime error: Vertex index in face out of range: [13,15,14]

any hints about what I’m doing wrong?
it’s obviously the face array, because if I ignore adding the faces it generates the vertexes just fine.

2 Replies
 lo1

consider what is happening in your loop when the last vertex is read.

 lo1

this code does does what your original code is trying to do

(
	local filepath = "C:\\custom_mesh.txt"
	local vertices = for l in (dotnetclass "system.io.file").readAllLines filePath collect 
	(
		local sp = filterString l ","
		[sp[1] as float, sp[2] as float, sp[3] as float]
	)
	local faces = for i = 1 to vertices.count-2 collect [i,i+1,i+2]
	local m = mesh vertices:vertices faces:faces
)

Though if you are expecting this to return the correct mesh based only on the vertex coordinates, it will not.
You will also need to save an explicit face list.

edit: unless of course your input is a single triangle strip data.