Any help on how to make a 3D modeler?

Blitz3D Forums/Blitz3D Programming/Any help on how to make a 3D modeler?

kochOn(Posted 2005) [#1]
I know this is a huge subject but I need to find some tips and starting point on how to make a 3D modeler.

- how to convert 2D mouse to 3D coordinates
- how to Draw vertex and lines around a 3D object
- how to Select a Polygon
- etc...

Maybe some tutorials exists on this subject?


octothorpe(Posted 2005) [#2]
2d to 3d: CameraPick()
3d to 2d: CameraProject()

AddVertex()
AddTriangle()
VertexCoords()
ClearSurface()
(Vertices and triangles cannot be deleted individually in Blitz3d, you need to either make them invisible or clear the entire surface and recreate all the other vertices and triangles that were on it.)

Select a polygon? What use are 2d polygons to a 3d modeler?


Scherererer(Posted 2005) [#3]
PickedTriangle() <- for selecting a polygon, PickedX(), PickedY(), PickedZ(), PickedEntity(), PickedSurface() will all help for selection, of course you will need to do a camerapick first.

drawing vertecies and lines:
Do a CameraProject() for every vertex, then draw an image for the vertex at the projected point with ProjectedX() and ProjectedY(). And to make the lines, use line() between the two points (you will have to temporaraly save the last location of a point).


big10p(Posted 2005) [#4]
I wouldn't use the Line command, myself - it's slow. Instead, just do a wireframe render on top of a normal render.

To draw and select vertices, I did this demo:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1008
Note that the method I use to select vertices can be improved. I was going to change it so that it did the following, but never got around to it. :)
- Find triangle mouse is pointing on.
- Calculate the distances from the mouse point to each vert in the triangle.
- Select the vert with the shortest distance.


jfk EO-11110(Posted 2005) [#5]
Maybe there's some useful code in the archives. eg. the CSG Modeler by M.Rauch, plus some mesh exporters. Although, CSP Modeling isn't exactly the same as vertex based works. Maybe you can combine both.


Scherererer(Posted 2005) [#6]
that is a good idea with the wireframe over normal render, but as I understand it, according to the docs wireframe should only be used for debuging, which could mean that there is sketchy support for it on some gfx cards. But, either way the wireframe system is much faster.

also, I almost forgot to mention, use CameraProjMode() to set the camera to an orthographic projection mode (no perspective).


big10p(Posted 2005) [#7]
according to the docs wireframe should only be used for debuging
True - I'd forgotten that, TBH. However, I'm not aware of anyone having a problem with wireframe rendering.

There is another slight problem with wireframe rendering on top of a normal render, too: z-fighting. This will mean the lines appear kinda sketchy. There are ways around this though.

You could slightly scale up the model for the wireframe render, or, just thinking about it now, you could:
1 - Do a wireframe render on it's own.
2 - CopyRect render to image (with mask set to same as CamerClsColor).
3 - Do normal render.
4 - Draw wireframe image over normal render (DrawImage).

This method might be a little on the slow side and VRAM hungry but I think it'd work. Would help if the render window (camera) was smaller than the screen.

[edit]I should point out that this method isn't perfect. :) You will still have the problem of ALL the lines of forward-facing tris being drawn, even when they should be occluded by other geometry... if you see what I mean.


Tom(Posted 2005) [#8]
Z buffer fighting is easy overcome by enabling Z buffer clearing like so:

Hold space to see difference

Graphics3D 800,600,32,2

cam = CreateCamera()
MoveEntity cam,0,0,-2

light = CreateLight(2)
PositionEntity light,20,20,-10

sphere = CreateSphere()
EntityColor sphere,255,0,0


While Not KeyHit(1)
	EntityColor sphere,255,0,0
	RenderWorld
	WireFrame True

	If KeyDown(57)
		CameraClsMode cam,False,True
	Else
		CameraClsMode cam,False,False
	End If

	EntityColor sphere,255,255,255
	RenderWorld
	WireFrame False
	Flip
Wend



cya
Tom


big10p(Posted 2005) [#9]
Good point, Tom. Didn't have my brain in gear. :)


kochOn(Posted 2005) [#10]
Thanks guys, I m going to check that. :)

köchOn