Home Coding, Scripting, Shaders

Get Editable Mesh Normals?

noekk
polycounter lvl 10
Offline / Send Message
noekk polycounter lvl 10
Hi guys, I'm programming an exporter and have run into a problem with getting the normals. For a box that's an editable mesh I have no problem getting the 8 vertices and the 12 faces (2 triangles for each side), I can't get the 12 * 3 = 36 normals though. Does anyone know how to do this?

There is also something bugging me, my exporter won't work with editable polys because the faces don't come back as triangles.

Thanks a lot.

PS - I'm using 3ds max 2015 and maxscript.

Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    For edit poly objects use obj = $Box001.mesh. obj will be a trimesh of the Editable Poly.

    To get normals use the Edit Normals modifier. It will work on both the Editable Mesh and Editable Poly objects. Here is an example.
    (
    	eMod = Edit_Normals()
    	modPanel.addModToSelection (eMod) ui:on
    	
    	for obj in selection do
    	(
    		vCount = eMod.GetNumVertices node:obj
    		
    		for v = 1 to vCount do
    		(
    			vPos = eMod.GetVertex v node:obj
    			format "Vertex:% Position:%\n" v vPos
    			
    			normalIds = #{}
    			eMod.ConvertVertexSelection #{v} normalIds node:obj
    			
    			normalIds = normalIds as array
    			for n in normalIds do
    			(
    				normal = eMod.GetNormal n node:obj
    				format "\tID:% Dir:%\n" n normal
    			)
    			
    		)
    	)
    	
    	deleteModifier selection eMod
    )
    And it returns this list
    Vertex:1 Position:[-16.8047,-9.14649,0]
    	ID:1 Dir:[0,0,-1]
    	ID:9 Dir:[0,-1,0]
    	ID:22 Dir:[-1,0,0]
    Vertex:2 Position:[16.8047,-9.14649,0]
    	ID:4 Dir:[0,0,-1]
    	ID:10 Dir:[0,-1,0]
    	ID:13 Dir:[1,0,0]
    Vertex:3 Position:[-16.8047,9.14649,0]
    	ID:2 Dir:[0,0,-1]
    	ID:18 Dir:[0,1,0]
    	ID:21 Dir:[-1,0,0]
    Vertex:4 Position:[16.8047,9.14649,0]
    	ID:3 Dir:[0,0,-1]
    	ID:14 Dir:[1,0,0]
    	ID:17 Dir:[0,1,0]
    Vertex:5 Position:[-16.8047,-9.14649,18.4046]
    	ID:5 Dir:[0,0,1]
    	ID:12 Dir:[0,-1,0]
    	ID:23 Dir:[-1,0,0]
    Vertex:6 Position:[16.8047,-9.14649,18.4046]
    	ID:6 Dir:[0,0,1]
    	ID:11 Dir:[0,-1,0]
    	ID:16 Dir:[1,0,0]
    Vertex:7 Position:[-16.8047,9.14649,18.4046]
    	ID:8 Dir:[0,0,1]
    	ID:19 Dir:[0,1,0]
    	ID:24 Dir:[-1,0,0]
    Vertex:8 Position:[16.8047,9.14649,18.4046]
    	ID:7 Dir:[0,0,1]
    	ID:15 Dir:[1,0,0]
    	ID:20 Dir:[0,1,0]
    OK
    


  • noekk
    Options
    Offline / Send Message
    noekk polycounter lvl 10
    Hi, thanks a lot for the help. I thought I would have to jump through hoops to get the triangles from editable polys. Instead of adding a normal modifier I decided to calculate the normals myself which wasn't difficult, the only thing I have to do is incorporate smoothing groups if they exist. I normally just export as .obj but I want to put the data on the clipboard to speed up workflow.

Sign In or Register to comment.