More crisp model edges

Blitz3D Forums/Blitz3D Beginners Area/More crisp model edges

Leto(Posted 2006) [#1]
Hoping to get some advice here. In this picture I've brushed the "top" in pic #1 with default BrushFX - it's very smooth and undefined.

Pic #2 is done with "BrushFX brush,4" (ie flat-shaded). Now the bevels are crisp and defined, but I've lost the smoothing on the very top square.

You can see my model in pic #3. I'd like to render the model so that the bevels are nicely defined whilst still retaining some basic shading from the light source.

I may be missing the terminology to find what I'm after. Do I need to separate the surfaces of the bevel and top-most square?




big10p(Posted 2006) [#2]
Yeah, you'll need to 'explode' the box so that all the sides, bevels and top are separate quads.

This is the only way I know of getting decent flat-shading in blitz. The flat-shading mode in blitz isn't much cop because it still uses vertex normals for lighting, instead of a surface normal. As such, you'll also need to make sure all your quads' vertex normals are perpendicular, like surface normals.


jhocking(Posted 2006) [#3]
Basically, what you're wanting to do is manipulate vertex normals, often referred to as smoothing groups. Exactly how this is done varies by the modeling tool, but as big10 suggests in most modeling tools you can detach faces to make them hard-edged. Your screenshot looks like Wings however, and you can't set smoothing groups in Wings. Nor, for that matter, does Blitz support smoothing groups in 3ds files; for vertex normals, you need to use b3d file format.

The way I would do it is model the shape in Wings and then fix up the smoothing in Ultimate Unwrap, but that's no longer sticking to free tools.


Bobysait(Posted 2006) [#4]
Or manually set the vertex Normals into blitz3D using VertexNormal(surf,VertexId,Nx,Ny,Nz) command, and UpdateNormals Mesh . But maybe, that would be quiet long !


Stevie G(Posted 2006) [#5]
Here's a couple of functions I use for flatshading ...

This unwelds the vertices to make better use of flatshading ...

Usage : MyMesh = MESHunweld( MyMesh )

Function MESHunweld( Mesh )

	Copy = CreateMesh()
	ns = CreateSurface( Copy )
	For su = 1 To CountSurfaces( Mesh )
		s = GetSurface( Mesh , su )
		For t = 0 To CountTriangles( s ) - 1
			v0 = TriangleVertex( s, t, 0 )
			v1 = TriangleVertex( s, t, 1 )
			v2 = TriangleVertex( s, t, 2 )
			Nv0 = AddVertex( ns , VertexX( s , v0 ) , VertexY( s, v0 ) , VertexZ( s, v0 ) )
			Nv1 = AddVertex( ns , VertexX( s , v1 ) , VertexY( s, v1 ) , VertexZ( s, v1 ) )
			Nv2 = AddVertex( ns , VertexX( s , v2 ) , VertexY( s, v2 ) , VertexZ( s, v2 ) )
			AddTriangle ns , Nv0 , Nv1 , Nv2
		Next
	Next
	FreeEntity mesh
	Return Copy

End Function	


This set's up the vertex normals per triangle rather than averaged normals of each vertice which shares the same space as updatenormals() does.

Usage : MESHnormals( MyMesh )

Function MESHnormals( mesh )

	For l = 1 To CountSurfaces(mesh )
		s = GetSurface( mesh , l )
		For t = 0 To CountTriangles( s )-1
			v0 = TriangleVertex( s, t, 0 )
			v1 = TriangleVertex( s, t, 1 )
			v2 = TriangleVertex( s, t, 2 )
			ax# = VertexX( s, v1 ) - VertexX( s, v0 )
			ay# = VertexY( s, v1 ) - VertexY( s, v0 )	
			az# = VertexZ( s, v1 ) - VertexZ( s, v0 )	
			bx# = VertexX( s, v2 ) - VertexX( s, v1 )
			by# = VertexY( s, v2 ) - VertexY( s, v1 )	
			bz# = VertexZ( s, v2 ) - VertexZ( s, v1 )	
			Nx# = ( ay * bz ) - ( az * by )
			Ny# = ( az * bx ) - ( ax * bz )
			Nz# = ( ax * by ) - ( ay * bx )
			Ns# = Sqr( Nx * Nx + Ny*Ny + Nz*Nz )
			Nx = Nx / Ns
			Ny = Ny / Ns
			Nz = Nz / Ns
			For v = v0 To v2
				VertexNormal s, v, Nx, Ny, Nz 
			Next
		Next
	Next

End Function


Both are not very versatile but suitable for my needs. You may be able to adapt them to suit yours.

Stevie


Dock(Posted 2006) [#6]
You just need to set your smoothing groups correctly for your model. Set the bevel edges to different surfaces from the top, sides, and other bevels. Then it will work fine.


Leto(Posted 2006) [#7]
Thanks a lot, guys. I'll look into all this advice!


simcenter(Posted 2006) [#8]
Oh my god, Stevie G.
Your work above was of incredible use to me. I have been screwing around with lights, looking for shadings, flat shaders, user libs, shadow functions, etc etc ect. All to no avail.

I just used your short codes and now my model looks awesome. Thanks so much.

Brian Heagney (simcenter)


Stevie G(Posted 2006) [#9]
Your welcome simcenter, they've been alot of use to me too! Got any screenies of your stuff?


simcenter(Posted 2006) [#10]
I actually don't know how to add an image to this thing yet, not only am I still a little new to Blitz and writing programs, but I'm also new to these forum type things. I'm not even sure how to quote things or use those little windows.

here's a question though, I noticed that since the Meshunweld function makes a copy of the original mesh I loaded, I'm losing all my textures.

I'm modeling in Sketchup, exporting to 3ds, which normally works great (for me) for importing into blitz...do you just not use textures, or do you texture after performing the unweld/normal


b32(Posted 2006) [#11]
You can find the forum tags in the FAQ section of the site. You can't directly post images. However you can link to an existing image on the web, and paste the url here. Optionally you can use the IMG tag (see FAQ) to show the picture in the post.
Here is an adapted version that (hopefully) keeps the texture data:



simcenter(Posted 2006) [#12]
You can find the forum tags in the FAQ section of the site.


thanks, I should have looked there long long ago.

for those other newbies like me looking to see the difference, I'm attaching two screen shots from a very very primitive scene. The first one as I imported it as a .3ds from Sketchup:


This next image is what the little house looks like after I include Stevie G's functions:

See what a great resource that is? And its so nice and user friendly too.

Also, I've been trying to use the function directly above (the one for keeping textures), but it seems to not work at line "VertexTexCoords ns, VertexU(s,vO),......."

Maybe I have misplaced the texture files, I don't know.


b32(Posted 2006) [#13]
Update: I thought I post the entire function again, because I noticed some other stuff too:
Function MESHunweld( Mesh )

	Copy = CreateMesh()
	For su = 1 To CountSurfaces( Mesh )
		s = GetSurface( Mesh , su )
		ns = CreateSurface( Copy )
		For t = 0 To CountTriangles( s ) - 1
			v0 = TriangleVertex( s, t, 0 )
			v1 = TriangleVertex( s, t, 1 )
			v2 = TriangleVertex( s, t, 2 )
			Nv0 = AddVertex( ns , VertexX( s , v0 ) , VertexY( s, v0 ) , VertexZ( s, v0 ) )
			Nv1 = AddVertex( ns , VertexX( s , v1 ) , VertexY( s, v1 ) , VertexZ( s, v1 ) )
			Nv2 = AddVertex( ns , VertexX( s , v2 ) , VertexY( s, v2 ) , VertexZ( s, v2 ) )
			VertexTexCoords ns, nv0, VertexU(s, v0), VertexV(s, v0), VertexW(s, v0)
			VertexTexCoords ns, nv1, VertexU(s, v1), VertexV(s, v1), VertexW(s, v1)
			VertexTexCoords ns, nv2, VertexU(s, v2), VertexV(s, v2), VertexW(s, v2)
			AddTriangle ns , Nv0 , Nv1 , Nv2
		Next
		ClearSurface s

		For t = 0 To CountTriangles( ns ) - 1
			v0 = TriangleVertex( ns, t, 0 )
			v1 = TriangleVertex( ns, t, 1 )
			v2 = TriangleVertex( ns, t, 2 )
			Nv0 = AddVertex( s , VertexX( ns , v0 ) , VertexY( ns, v0 ) , VertexZ( ns, v0 ) )
			Nv1 = AddVertex( s , VertexX( ns , v1 ) , VertexY( ns, v1 ) , VertexZ( ns, v1 ) )
			Nv2 = AddVertex( s , VertexX( ns , v2 ) , VertexY( ns, v2 ) , VertexZ( ns, v2 ) )
			VertexTexCoords s, nv0, VertexU(ns, v0), VertexV(ns, v0), VertexW(ns, v0)
			VertexTexCoords s, nv1, VertexU(ns, v1), VertexV(ns, v1), VertexW(ns, v1)
			VertexTexCoords s, nv2, VertexU(ns, v2), VertexV(ns, v2), VertexW(ns, v2)
			AddTriangle s , Nv0 , Nv1 , Nv2
		Next
		
	Next
	FreeEntity Copy
	Return Mesh

End Function

The function works differently from the original. The original function should be called like this:
mesh = MeshUnweld(mesh)
But this version should be called like this:
MeshUnweld mesh