Notifications
Clear all

[Closed] Vertex Normals Problem.

Anybody have any ideas on whats wrong with my most recent code posting? If I can figure out this normals/smooth group issue, I’ll be set.

If nobody can help me, can someone at least point me to some resource where I can learn how smooth groups and normals in a mesh are structured and how to access those things?

Where you wish to see results of this script? Do you creating another 3d application?

No smoothing? What you mean? Geom is flat shaded or shading is wrong?

I posted a link above and an excerpt from the specs of the format I’m trying to export to. I think the sample code you posted is the right direction for me but I have no idea how to adapt it to my code. I have all the framework for a decent exporter but I could really use someone with some more experience that would be able to look at the file format (linked above) and my code (the whole script if possible) and advise me on the problems i’m having. I may even be willing to paypal a small donation if someone could help me.

Can you post simple file in this format here?

according to obj8 triplet format you don’t need to do anything with faces smoothing groups. If you want to get Data for SMOOTH rendering you have to use Face Render Normals, if you want to get FACET Data you have to use the Face Normal for all three corners.
Render Normals are stored with taking to account the face normal values and face smoothing groups.

here is a code to collect obj8 data from any geometry object:


fn formatOBJ8_split node smooth:on = if iskindof node GeometryClass do
(
	local mesh = copy node.mesh
	local triplets = for f in mesh.faces as bitarray collect
	(
		mverts = getFace mesh f
		tverts = getTVFace mesh f
		
		normals = if smooth then meshop.getFaceRNormals mesh f
		else
		(
			normal = getFaceNormal mesh f
			#(normal,normal,normal)
		)
		triplet = for k=1 to 3 collect
		(
			pos = getVert mesh mverts[k]
			uvw = getTVert mesh tverts[k]
			data = #(pos.x, pos.y, pos.z, normals[k].x, normals[k].y, normals[k].z, uvw.x, uvw.y)
		)
	)
)

and rebuild the mesh using obj8 data:


fn creatMeshUsingOBJ8_split data =
(
	local numFaces = data.count
	local numVerts = numFaces*3
	
	node = mesh name:"FromOBJ8" numverts:numVerts numfaces:numFaces
	setNumTVerts node (numFaces*3)
	buildTVFaces node
	for f=1 to numFaces do
	(
		verts = 3*(f-1)+[1,2,3]
		setFace node f verts
		for k=1 to 3 do
		(
			setVert node verts[k] [data[f][k][1],data[f][k][2],data[f][k][3]]
			setNormal node verts[k] [data[f][k][4],data[f][k][5],data[f][k][6]]
			setTVert node verts[k] [data[f][k][7],data[f][k][8],0]
		)
	)
	node
)
/*
t = teapot()
data_smooth_on = formatOBJ8_split t smooth:on
data_smooth_off = formatOBJ8_split t smooth:off

creatMeshUsingOBJ8_split data_smooth_on
creatMeshUsingOBJ8_split data_smooth_off
*/

I split obj8 data on triplets (per face) and triplet on verts (per face corner). Real OBJ8 format probably stores whole data as one massive and the code might be:


fn formatOBJ8_combo node smooth:on = if iskindof node GeometryClass do
(
	local mesh = copy node.mesh
	local triplets = #()
	for f in mesh.faces as bitarray do
	(
		mverts = getFace mesh f
		tverts = getTVFace mesh f
		
		normals = if smooth then meshop.getFaceRNormals mesh f
		else
		(
			normal = getFaceNormal mesh f
			#(normal,normal,normal)
		)
		for k=1 to 3 do
		(
			pos = getVert mesh mverts[k]
			uvw = getTVert mesh tverts[k]
			data = #(pos.x, pos.y, pos.z, normals[k].x, normals[k].y, normals[k].z, uvw.x, uvw.y)
			join triplets data
		)
	)
	triplets
)

I tried to keep the code clear and didn’t care about performance. The code should be optimized and be 2-3 times faster for large meshes but you can do it yourself.

You mean my code? Or a xplane model or a max file?
Edit, wow denisT just saw your post…I’ll have to digest it and let ya know…awesome…are you specifically referring to x-planes obj 8?

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

if you are asking about optimization I meant my code that I gave you as a sample.

(@denist)
Joined: 11 months ago

Posts: 0

I’ve never worked with x-planes OBJ8 format. I’ve read the link that you posted above.

Sorry about all the confusion there in my replies…I was on my phone and out and about…the “You mean my code? Or a xplane model or a max file?” reply was actually to miranDMC.

Question…will the Face Render Normals option make the obj8 output look the same as if I were using the smooth groups in max?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

Face render normals represent the mesh current normals data. Which is face normals averaged by face smoothing groups. If you will correctly do the same in your code technically you have to get the same values. But… max allows to edit normals with some other tools (edit normals modifier for example). Render normals reflect these changes as long as the mesh was not recomputed. So the render normals give you more accurate data then own calculation.

I’ve come to find that my biggest problem is indexing the vertices. I need a way to organize the vertices that I loop through and build the indices according to the mesh. Are there any examples or tutorials or anything out there (even if someone wants to help me figure it out off this forum) how I can optimize my vertex records and create an optimized index listing?

Page 2 / 2