PDA

View Full Version : Is OBJ or 3ds export possible ?



Macros The Black
06-03-2009, 08:33
Have a question or two regarding the export of OBJ or 3ds files

1. Is it possible ?

2. I am using list and primitive objects to generate a tree using Petr's script.
I have created a user interface to control tree parameters and then generate trees
based on these parameters.
Can the data generated by the script then be captured and exported to OBJ or 3DS ?

3.Are there any examples of how to implement Exporting or Saving of OBJ or 3DS files ?

4. I noticed that thinedge supports export to these formats and would like to know if the
export features will be implemented in TBGL

I know this is probably something that is relatively easy but forgive me for the lack of
knowledge in this area as i am mainly a 3d modeller and have just got into scripting recently.

Ask me to make a multi textured ,high resolution ,3d model of a Banshee = No Problem :eusadance:

Ask me to Script a function to save my life = I am dead :(

Petr Schreiber
06-03-2009, 08:58
Hi Macros,

TBGL does not feature this, as it is not possible to do it for geometry defined using immediate mode/display lists - this is sent directly to driver and archived nowhere.

But there is still hope, multiple options :)

OBJ format is very simple, so it is not that hard to write custom exporter.

Take following code:


TBGL_BeginPoly %GL_TRIANGLES
TBGL_Vertex -1, -1, 0
TBGL_Vertex 1, -1, 0
TBGL_Vertex 0, 1, 0
TBGL_EndPoly


It can be "translated" to OBJ as following:


# TRIANGLE
# List of vertices
v -1.000000 -1.000000 0.000000
v 1.000000 -1.000000 0.000000
v 0.000000 1.000000 0.000000

# List of faces pointing to vertex list above
f 1 2 3


You can also make list of texture coordinates and even define material (texture, color) via MTL file.

OBJ does not support geometric primitives or transformations, so for exporting cylinder, you would have to create simple triangle mesh for it, and then postprocess vertices via matrix multiplication - you would basically duplicate push/pop matrix, translate, rotate commands.

OBJ format specification can be found on the web, for example here:
http://local.wasp.uwa.edu.au/~pbourke/dataformats/obj/

VRML
Now that you are scared from doing ton of work, there is VRML - it is very close to OpenGL representation of data, includes primitives and transformations. I guess this would be the most straightforward way, but I am not sure if your 3D modeler supports import from this.



TBGL_PushMatrix
TBGL_Translate 2, 2, 2
TBGL_Cylinder 2, 2, 4
TBGL_PopMatrix


would become



Separator {
translation {
translation 2, 2, 2
}
Cylinder {
radius 2
height 4
}
}

... or something like that :)


Petr

Macros The Black
06-03-2009, 15:43
If have understood correctly the TBGL_cylinders that make up the tree branches cannot be exported
and because the leaves are a display list then they cannot be exported either is that right ?

So i would have to create the cylinder by defining its vertices?

If i did this how would i then change the length\radius of cylinder dynamically ?

About the code example you have written in your post

TBGL_BeginPoly %GL_TRIANGLES
TBGL_Vertex -1, -1, 0
TBGL_Vertex 1, -1, 0
TBGL_Vertex 0, 1, 0
TBGL_EndPoly

Isnt this a display list ?

I have attached the Treegenerator GUI script from the other Treegenerator post.

Would you be able to post an example of how to implement the simple triangle method you have described into the tree generator?


As for the export problem i will probably have to have an attempt at coding my own exporter for .OBJ
Although i am not sure about where to start.


I dont mean to be a pain i just figure its better to ask someone with more knowledge on the subject.

Petr Schreiber
06-03-2009, 16:34
Hi Macro,

all you have to do is:
- define cylinder via triangle vertices
- cast transformations via transformation matrices

Here is simple example of defining points for Cylinder:


'
' One of the possible ways to generate Cylinder, vertex by vertex
' Petr Schreiber, started on 03-06-2009
'

Uses "TBGL" , "Math"

FUNCTION TBMAIN()
LOCAL hWnd AS DWORD
LOCAL FrameRate AS DOUBLE

' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow

' -- Initialize lighting
TBGL_UseLighting %TRUE
TBGL_UseLightSource %GL_LIGHT0, %TRUE

tbgl_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1

' -- Resets status of all keys
TBGL_ResetKeyState()

' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate

TBGL_ClearFrame
TBGL_Camera 15, 15, 15, 0, 0, 0

TBGL_Color 255, 128, 0
RenderCylinder(1, 2, 3)

TBGL_DrawFrame

' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow
END FUNCTION

SUB RenderCylinder( BYVAL lowR AS EXT, BYVAL hiR AS EXT, BYVAL height AS EXT )
LOCAL i AS EXT
LOCAL n AS LONG, px AS SINGLE, pz AS SINGLE, x AS SINGLE, y AS SINGLE, z AS SINGLE
LOCAL j AS LONG
LOCAL theta1, theta2, theta3 AS SINGLE

n = 24

j = (( n / 2 ) - 2 ) / 2

theta1 = j * (Pi*2) / n - (Pi/2)
theta2 = ( j + 1 ) * (Pi*2) / n - (Pi/2)
TBGL_BeginPoly %GL_QUAD_STRIP
FOR i = 0 TO n

theta3 = i * (2*Pi) / n

x = COS( theta2 ) * COS( theta3 )
y = SIN( theta2 )
z = COS( theta2 ) * SIN( theta3 )
px = lowR * x
pz = lowR * z
TBGL_Normal x, y, z
tbgl_TexCoord2D - theta3 * lowR, 0.0

TBGL_Vertex px, 0.0, pz

x = COS( theta2 ) * COS( theta3 ) ' theta1
y = SIN( theta2 )
z = COS( theta2 ) * SIN( theta3 ) ' theta1
px = hiR * x
pz = hiR * z
TBGL_Normal x, y, z

tbgl_TexCoord2D - theta3 * lowR, height
TBGL_Vertex px, height, pz
NEXT i
TBGL_EndPoly 'GL_QUAD_STRIP

END SUB


But this is just to help you understand it "visually", for OBJ you would have to generate separate list of vertices and faces of course.

Do you think VRML is no way? I sadly do not have time resources to help more at this time, but feel free to ask.


Petr

Macros The Black
07-03-2009, 12:04
Hi again
Vrml isnt really suitable as i would like to make it easy to use trees in many different 3d apps and OBJ is the most cross compatible format.

Is it possible to perform the same tree generation using M15 models, For example if i modelled the cylinder and leaves in thin edge, and saved them as seperate M15 files e.g - Cylinder.M15 and Leaves.M15

Could i then perform the same transforms and generation using the M15 models instead of display lists?

Then i should be able to export out as OBJ ?

Petr Schreiber
07-03-2009, 15:53
Hi Macros,

TBGL_m15SaveModel function could be done ... but I think it would be easier to do it directly to OBJ, as m15 would not help you with the most tricky parts - translations + rotations.

Translations and rotations can be retrieved from OpenGL matrices, I can look into it, but it will take me some days as I am little bit short in time.


Petr

Macros The Black
07-03-2009, 17:03
I am trying to understand how to do this but im getting confused.

If i create the cylinder using Polygon modeling methods eg.
(The code below just creates a polygon)

TBGL_PUSHMATRIX
TBGL_BEGINPOLY %GL_POLYGON
TBGL_NORMAL 0, 0, 1
TBGL_TEXCOORD2D 0, 0
TBGL_VERTEX - 1, 0, 0
TBGL_TEXCOORD2D 1, 0
TBGL_VERTEX 1, 0, 0
TBGL_TEXCOORD2D 1, 1
TBGL_VERTEX 1, 1, 0
TBGL_TEXCOORD2D 0, 1
TBGL_VERTEX - 1, 1, 0
TBGL_ENDPOLY
TBGL_POPMATRIX

I should be able to recall the data to export it to OBJ shouldnt i ?

i am having a bit of trouble distinguishing between display lists and polygon methods.

Are they the same thing?

For example if i have created the polygon above inside a display list will the data be retrievable or not?

If not couldnt i just create a function called BP() that builds the cylinder from polygons and then call the function instead of using TBGL_CYLINDER for example:

FOR i = 1 TO levels

TBGL_CYLINDER radiusS, radiusE, length CHANGE THIS TO BP() Function
TBGL_TRANSLATE 0, length, 0
TBGL_ROTATE openangle, 0, 0, 1
TBGL_ROTATE twist, 0, 1, 0
TBGL_PUSHMATRIX
TBGL_ROTATE - openangle * 2, 0, 0, 6
IF i = 1 THEN
DrawBranch( radiusE, length, levels - 1, - openangle, twist )
ELSE
DrawBranch( radiusE, length, levels - i, openangle, twist )
END IF
TBGL_POPMATRIX
radiusS = radiusE
radiusE = radiusS - startRadius / levels
length = length - startlength / levels
NEXT
TBGL_POPMATRIX

I know the code above would need more refinement than just adding the BP() function but i am just concentrating on getting the cylinder working first and will worry about rest later.

I had an idea
How about changing the scaling of the BP() function cylinder to adjust radius and length

If i adjust the scaling of the BP() function created cylinder along x axis and z axis to change the radius and scaling y axis for length it should work , and with the data generated from this i would be able to export to OBJ wouldnt i ?

The only problem is i am not sure how to do this.
Once again thanks for any help provided.

Petr Schreiber
07-03-2009, 18:55
Macros,

let me explain a bit how definition of TBGL geometry works.

Immediate mode
Geometry defined between TBGL_BeginPoly / TBGL_EndPoly.
You define objects vertex by vertex. Definition is redirected to driver, no storage of data is performed
Speed rating: slowest, because you use lot of function calls to define object. It has educative value

M15 Models
Geometry defined on the fly using TBGL_m15* commands, or loaded from file.
Geometry is rendered in more optimized way, info about vertices is stored.
Speed rating: fast

Geometry primitives
Geometry defined using single call like TBGL_Sphere, TBGL_Box, ...
Rendering approach used differs from object to object, internal data are not accessible by TBGL programmer.
Speed rating: varies

And in the end we have special class, encapsulating all of the above:

Display lists
It allows to "cache" geometry created via any of previously described approaches using TBGL_NewList / TBGL_EndList.
You create display list before rendering, then call group of cached commands via TBGL_CallList.
Speed rating: fast, thanks to fact geometry is transfered to driver once, not each frame.

As you see, all those approaches are +/- geometry-to-driver things.
When you need to output raw data to file, you should define custom data structures and write them to file later.

How openGL / TBGL knows how to draw?
It internally works with matrix stack.

TBGL_Translate shifts actual "3D cursor" position
TBGL_Rotate turns actual "3D cursor" orientation
TBGL_Scale scales actual coordinate system.

So you first define transformations, and when you define geometry later, all its vertices are postprocessed by matrix which reflects current position, orientation and scaling.


Petr

Macros The Black
07-03-2009, 19:07
So by defining a primitive in a display list the the data would be retrievable and able to be exported?

Or would i just define the vertices to make the cylinder inside the display list and then retrieve the data when needed?

I know im asking a lot of questions but i am still trying to understand the basics while getting in well over my head.

Petr Schreiber
07-03-2009, 19:17
Hi Macro,

it is important to ask questions, no problem.

Answer to your question is no - driver caches it in vendor specific form, so no way to get it back safely.

I think the key, in this case, is understanding the algorithm as a such, and reconstruct the vertex positions using own math routines, there is no need for *GL.
You are lucky as ThinBasic supports matrix arithmetics.

Growing the tree in this case is nothing else than set of elemental translate-rotate transformations, casted on 1 scaled object - cylinder.


Petr

Macros The Black
08-03-2009, 06:56
OK i have tried implement the cylinder code that you posted
just to get an idea of how things work but i keep getting weird results and i am unsure of why.

The code works and generates a tree but all the vertices get messed up and look wierd.
I think i know what the problem is but i am not sure how to fix it.
The impression i got is that somehow the Length,Levels,Size,Angle and twist attributes of the drawbranch function
are having an adverse effect on the generated cylinder but i cannot figure out which is causing the problem.

I will say now that maths isnt one of my strong points so it takes a bit for me to understand whats actually happening in the code.

I understand how to create a polygon but thats where i start to get lost.
I keep getting lost in the maths side of things eg. PI,COS,SIN
and the calculations they perform.

I have attached the tree generator with the UI that uses the cylinder code that you posted so you can see my wierd results
when using the code.
If you can fix this that would be great but i dont expect you to code my app for me so dont feel you need to do this.

About VRML
Can this format export all the data for the tree with textures.
Also you said VRML supports primitives and transformations , so if i set up to export to VRML i would be able to use the original code with primitive cylinder and all the tree data would be able to be exported.
I have not had much to do with the VRML format as until recently most of my time has been dedicated to high end modeling and VRML didnt really suite my goals.
However if this format can carry all the data for the tree so that textures and mapping are preserved and not have to be set up again in whatever modeller or enviroment the tree models are used i would be interested in using VRML.

thanks for any help.

Petr Schreiber
08-03-2009, 10:41
Hi Macros,

there are few minor problems :
- RenderCylinder always with parameters for length of 1, width of 1
- building font each time you render frame
- creating entity each time you create frame
- specifying back color each time frame is rendered, not needed, TBGL works like state machine
- why is it called D3D Tree Generator? ;)

... and I think there is still no code related to the export side of things.

I have one idea you will not like me for, but I feel you chose very complex script as your first one in thinBasic, especially when you say you are not strong on math.

So - what about putting this on hold now, starting new, easier project where you will learn how to link data structures and graphics together, how transformations work, and then reimplement the tree designer together?

Without knowledge of SIN/COS/Matrices it is nearly impossible to finish this project successfully.

Regarding VRML - it can use textures, I will have a look at it, last time I checked it in past century :)
One thing - I do not think the trees generated by this algorithm can be considered profi enough for hi-end modeling - you can see the cylinders are not joined in any way, creating not continuous mesh. I designed it for real time, not state of the art visualisations.


Petr

Macros The Black
08-03-2009, 17:32
Thanks for the tips .

I have been thinking about strating from scratch so that i learn the right way of doing things.

D3D tree generator just a temp name until i think of something to call it if i ever get it finished.

I do agree about the trees generated not being the best for high end realistic renders but they are suited to
stylized renders and would also look good when using toon shaders.

Would it be possible to create the tree as a continous mesh ?
If so what would be the best way to implement this ? (so i at least know where to start)

The continuos mesh idea is the style of tree that im interested in making as it would be more suited to high end graphics.

Can i make a .M15 model by defining its vertices in TBGL ,Is this possible ?

If thats possible i should be able to save the new model as .M15

Its not OBJ export but its a start!

I have also looked at OGLE and GLIntercept.
Are these compatible with TBGL.
Would it be possible to implement the same sort of thing ?

Petr Schreiber
08-03-2009, 17:59
Hi,

regarding continous mesh - sure it is possible, but at the time I am not sure how, I did not examined this possibility.

You can make M15 model using TBGL_m15* commands - have a look to help file. It is slightly different principle.

Then you can go through the vertices and generate OBJ file.

If you will manage to create correct tree model, I will show you how to go through M15 in memory and output OBJ to file.

GLIntercept is nice hack, I use it from time to time for checking efficiency of code :)


Petr

Macros The Black
10-03-2009, 13:36
Hi again
I have made a start on trying to define a cylinder using .M15setvertexxyz
So far i have got the top and bottom done but i dont really know how to join them.
This is my code so far.


sub CYL( count as long)

local i as long
local vertexIndex as long


tbgl_m15SetModelVertexCount( 1, count * 12 )

' We will create quads, this sets white color to whole buffer
tbgl_m15SetVertexRGB( 1, 1, count * 12, 128, 128, 128 )



for i = 1 to count


' Lets create base
incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, 1, 0, 1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,1)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, 0, 0, 2 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,1)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, -1, 0, 1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,1)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, -1, 0, 1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,1)


incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, -1, 0, -1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,1)



incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, 0, 0, -2 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,1)

tbgl_m15SetVertexPStop( 1, vertexIndex, 1 )



' Lets create top
incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, 1, 5, 1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,2)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, 0, 5, 2 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,2)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, -1, 5, 1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,2)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, -1, 5, 1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,2)


incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, -1, 5, -1 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,2)



incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, 0, 5, -2 )
TBGL_M15SETVERTEXLAYER (1,vertexindex,2)




tbgl_m15SetVertexPStop( 1, vertexIndex, 1 )
TBGL_M15RECALCNORMALS 1,1
next

end sub

Does this look like the right sort of code to make a cylinder from .M15setvertexxyz commands

OK while writing this i had an idea about where i am going wrong but im not 100% sure
I think maybe i should be defining the vertices in a different order.

Also had an idea for handling .M15
How about

TBGL_M15SETPOLYEXTRUDE

This way you would only have to create one poly then extrude it to create objects like cylinders,boxes etc.
It could also be set up to extrude to a defined path.
This is only a suggestion as i have no idea how hard it would be to implement.

Petr Schreiber
10-03-2009, 14:35
Hi Macros,

your code was almost ok, but here is complete cylinder.
It is very hard to create circular base without SIN/COS.



'
' Cylinder
' Petr Schreiber, started on 03-10-2009
'

Uses "TBGL", "Math"

FUNCTION TBMAIN()
LOCAL hWnd AS DWORD
LOCAL FrameRate AS DOUBLE

' -- Create and show window
hWnd = TBGL_CreateWindowEx("Cylinder - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow


TBGL_UseLighting %TRUE
TBGL_UseLightSource %GL_LIGHT0, %TRUE

tbgl_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1
TBGL_m15InitModelBuffers 1, 10000

' -- Resets status of all keys
TBGL_ResetKeyState()

' -- Create cylinder
CYL(24, 4, 1)

' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate

TBGL_ClearFrame
TBGL_Camera 15, 15, 15, 0, 0, 0

TBGL_Color 255, 128, 0
TBGL_Rotate gettickcount/10, 0, 1, 0

' -- Render cylinder
tbgl_m15DrawModel 1

TBGL_DrawFrame

' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow
END FUNCTION

sub CYL( qualityStep as long, radius as double, height as double )

local i as long
local vertexIndex as long

dim angleJumpRad as double = DegToRad(360/qualityStep)

tbgl_m15SetModelVertexCount( 1, qualityStep*2 + qualityStep*4 ) ' 2 * base + sides
tbgl_m15SetVertexRGB( 1, 1, qualityStep*2 + qualityStep*4, 255, 128, 64 )

' -- Bottom
for i = 0 to (qualityStep-1)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, cos(i*angleJumpRad)*radius, 0, sin(i*angleJumpRad)*radius )

next
tbgl_m15SetVertexPStop( 1, vertexIndex, 1 )


' -- Top
for i = 0 to (qualityStep-1)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, cos(i*angleJumpRad)*radius, height, sin(i*angleJumpRad)*radius )

next
tbgl_m15SetVertexPStop( 1, vertexIndex, 1 )

' -- Sides
for i = 0 to (qualityStep-1)

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, cos(i*angleJumpRad)*radius, 0, sin(i*angleJumpRad)*radius )

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, cos(i*angleJumpRad)*radius, height, sin(i*angleJumpRad)*radius )

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, cos((i+1)*angleJumpRad)*radius, height, sin((i+1)*angleJumpRad)*radius )

incr vertexIndex
tbgl_m15SetVertexXYZ( 1, vertexIndex, cos((i+1)*angleJumpRad)*radius, 0, sin((i+1)*angleJumpRad)*radius )

tbgl_m15SetVertexPStop( 1, vertexIndex, 1 )
next



tbgl_m15RecalcNormals 1, %TBGL_NORMAL_PRECISE

end sub


Regarding Extrude - I think this is quite application specific. Problem is in order of vertices, which determines side the normal points to.

Most editors which support it have this under their control, as they create "nice" primitives. But m15 buffer is general purpose, so it could give odd results. Will think about it.


Petr

Macros The Black
10-03-2009, 15:51
Thanks for that.

I think the tree should be relatively easy from here as i should be able to set layers and take control of them to perform transforms

Mainly to set the length and scale the radius of the cylinder.

This is possible isnt it ?

Or will i have to call the actual vertices to change transforms?

Petr Schreiber
10-03-2009, 15:56
Macros,

I am afraid not - quioting myself from march 07:


...as m15 would not help you with the most tricky parts - translations + rotations.


You can store data in M15 structure if you want, but you have to do the rotations/translations/scaling yourself, via manual calculations.

"Scaling" radius and length is simple, but positioning the rotated branches not so easy.


Petr

Macros The Black
11-03-2009, 01:26
Yeah i sort spoke before looking at the code properly.
I have almost figured it out.

I have got the cylinder to work but
the positioning is a bit out and i am getting
wierd results at the moment.

will keep trying as i think i am almost there.

Macros The Black
11-03-2009, 11:43
Alright i have got the .M15 cylinder working alright but i have stuffed the texturing.
Now all i get is a black tree.(or orange if i leave the TBGL_M15SETVERTEXRGB in the code)

The problem is that the texture for the is not working and in turn is effecting the texture for the leaves.
I have tried several ways of trying to texture the cylinder but keep getting strange results.

The is a cut down version of the script i am using that just includes the basic tree functions and the implemented .M15 cylinder.
Things seem to work ok apart from the texture issue.
Currently it lags a bit while loading, i think this is caused by my texture problems.

Petr Schreiber
11-03-2009, 16:13
Hi Macros,

nice surprise, good progress!

Few hints to "make it work":

- use TBGL_m15InitModelBuffers 1, 10000 just once in program initialisation ( right after binding canvas )

- use TBGL_m15SetVertexTexN( <model>, 1, <vertexcount>, <textureID>) to set texture, m15 buffers are isolated objects not reacting on TBGL_BindTexture

- use TBGL_m15SetVertexRGB( <model>, 1, <vertexcount>, <R>, <G>, <B>) to set color, must be other than black else texture will not be visible ( 255, 255, 255 ) recommended


Petr

Macros The Black
11-03-2009, 17:38
Thanks for the tips
have got the textures applied and they change alright but the scaling is wierd.

Textures seem to be scaled really large so that they sort of just display as colours,No Detail.
cannot seem to get the coordinates right.

Should i be using TBGL_TEXCOORD2D at all or should i be setting the textures up using .M15 commands ?

The problem with the leaves still remains.
It seems like the texture for the branches overrides the leaves texture.
Any ideas as to what could be causing this ?

the scripts attached

Many thanks for all the help that you have given me already.

Petr Schreiber
11-03-2009, 19:36
Hi Macros,

good, the problem with texture coordinates is in fact you do not specify any.

Use TBGL_m15SetVertexTexXY in the same way you would TBGL_TexCoord2D - that means for each vertex.
You can extract the proper coordinates from the first cylinder code I posted earlier in this thread ( that non M15 ).

Leaf textures override - will check.


Petr

Macros The Black
12-03-2009, 14:44
I have posted the script i am working with (just the cylinder).
I would just like to know if i am heading in the right direction with the texture coords.
Not sure if i am assigning the right values to the right vertices.
The script does run but no textures are displayed.

Scripting X,Y coords isnt difficult as i understand the basics, like where 1,1 would have me landing in x,y coords when assigning TBGL_M15SETVERTEXTEXXY to a cube (made from same technique as the .M15 cylinder), but when it comes to mapping around a cylinder i am a bit lost.
I know its something to to with the radius and hieght values but as i am new to scripting this kind of thing it is quite confusing.

I think its important to say now that first and foremost i am a 3D modeling and texture artist that has learnt using 3ds max.
This is why i am having difficulty with the texturing aspect (being a 3ds max user i am used to just assigning uv map and applying material). Scripting is something i have just started to explore in more depth and while i understand a lot of whats going on i get lost in the math sometimes.(maybe need to refresh what i know and probably learn more)

I have worked with darkbasic for a little while and also other game creation engines such as Gamestudio A7,Irlicht,OGRE and
so on, but mainly as modeller and texture artist with very limited need for scripting.
Not that i didnt have to do any scripting but the things i had to script where always very simple.

While these are good they dont really suite the kind of developments i want to undertake, this is my reason for being so interested in Thinbasic and TBGL.
I have a pretty good understanding of scripting the windows UI and controls and the fact that they can be used so easily to control the TBGL scene is a big plus.
I can only see a bright future for Thinbasic and TBGL.

Petr Schreiber
12-03-2009, 20:23
Macros,

thanks for your kind words.

I just returned from Uni, will check your code.


Petr

Petr Schreiber
12-03-2009, 20:53
Hi,

I found the reasons for troubles, there were 2:
- using TBGL_m15SetVertexTexN( 1, 1, vertexIndex, 1 ) on the start is not good, as vertexIndex is 0 in that part
- other problem was in fact you set just one coordinate for each vertex, forgetting the second. I used 3DS Max only for 30 days (trial version), but I think this texture coordinates are called UV there. So you set just U and not V.

- I corrected problem with different radiuses ignored by cylinder

To save few polys maybe you could render just sides, not bases, that's up to you of course.


Petr

Macros The Black
13-03-2009, 08:40
Ok .M15 cylinder works.
.M15 Cylinder Textures work.

Still having problems with the leaves.

The script is attached.

I have scripted a polygon using .M15 commands to use for the leaves but cant get it to work.
The script seems to be right but the created polygon is not displayed.
The script for the polygon is in the attached script but it is not being used at the moment.


I have read over your description of how TBGL geometry works and have a question.

If using the original code is it possible to export the leaves that are created via TBGL_BEGINPOLY if they are part of a display list.
This way i will not have to change much, otherwise i will keep trying to get the .M15 polygon to work.

------------------------------------------------------------------------------------------------------------------------------------------

Lightning v1

I have also been working on a script to create lightning using %GL_LINE_STRIP and vertex coordinates.
Not very complex at the moment but i will post script so you can see what i have created so far.
The lightning works alright but i need to sort out timing issues.
Currently you can call a lightning bolt by pressing 2 but it is still under development so it doesnt work properly yet.
The biggest trouble is that it creates more than one lightning bolt.
I know this is something to do with how i have made the lightning.
When it is called i want just one bolt but i have to spend more time to get this right.
The final script will have the lightning being called at random start positions at cloud level and targeting random position on the ground or terrain.

There is also was bit of lag on the glow effect i have used but this isnt really important at the moment.
I will probably try using Shaders to get the lightning to glow correctly.
I read somewhere that TBGL can use Nvidia FX composer shaders.
I know enough to get a good glow happening in FX composer so it would be handy to be able to use the FX file.
What type of FX files are compatible with TBGL as you can output a few different types of FX file from FX composer ?

Petr Schreiber
13-03-2009, 09:52
Hi Macros,

nice code!

I need to put one thing straight - there is no "autoexport" for any of TBGL geometry, so it all depends on how you design it.

Problem with Dleaf was in 2 things:
- you use TBGL_m15InitModelBuffers to define space for 1 model slot, while you define leaf in second
- little mistake in TBGL_m15SetVertexTexN set texture only to last vertex
- not increasing vertexIndex caused placing new vertices at invalid item of 0

Regarding lightnings - cool stuff!
Just one thing - could you create new thread for them, so this would be for trees and another for lightnings?

Glow can be implemented even with pure render2texture, I did it multiple times and posted samples here.
Info on rendering to texture is in ThinBasic Journal 2 article about motion blur.

Regarding CG shaders, yes it is possible:
http://community.thinbasic.com/index.php?topic=1708.0
... but did not tested it too much.


I attach new code for you,
Petr

ErosOlmi
13-03-2009, 10:59
Macros,

maybe you already know but worth to mention: we have a download section called "thinBasic Bonus Packs" at http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=viewcategory&catid=5
You will find there 2 downloads with tons of TBGL example. Maybe you will find new features and get even more inspirations.

Thanks a lot for your nice scripts.
Ciao
Eros

Macros The Black
13-03-2009, 11:47
Thanks for that Petr

But without your help i would still be trying to make a cylinder.

So now that everything is defined using .M15 commands i will be able to export to OBJ via custom export script is that right ?

There is still a lot of work i have to do on textures for the branches and leaves (i intend to include a larger library of textures)
as well as completing UI and controls for tree definition.

I have already got the basics done on the UI and know how to link all the Values to be adjusted.(A lot easier than expected)

I will also include controls to choose which textures are used for branches and leaves instead of leaving them random.

Just a quick thought.
When i mentioned doing the tree's with continous mesh it got me thinking.

All the vertices for the cylinders are defined by .M15 commands.

When the tree is generated could the data for the tree (branches) be evaluated and used
to create (generate) continous mesh from the vertices that is then displayed instead of the cylinders ?

I am not sure if this is possible but it sounds good in theory.

I will make a new post for the Lightning script but it is still really basic and
there is not much in way of controlling it.

Well now the artistic side of things needs some attention , many hours of working on photos with Gimp to get Texture library done. (really just need a short break from looking at scripting)
------------------------------------------------------------------------------------------------------------------------------------------------------

Eros

Thanks for the pointer.
I have downloaded the bonus packs and have been looking over them as i have been working on the tree generator.
Also thanks for the kind words about my scripts but a lot of credit has to go to Petr as he has basically guided me through it.
The Lightning script is my first attempt at scripting with no help.

------------------------------------------------------------------------------------------------------------------------------------------------------

Petr Schreiber
13-03-2009, 15:03
Hi Macros,

Regarding your M15-fication of code - you are 50% done, the other job is to actually get the rotated cylinder coordinates. Maybe hybrid OpenGL way could be used, by retrieving current matrix at each pass of the generation and multiplying calculated vertices by that.

In theory - when you have vertices from radiuses, you could try to generate connection triangles between them easily, by joining nearest vertices.
Not that it would look good I am afraid :)

I am going to look at the lightning now.


Petr

Macros The Black
13-03-2009, 15:22
Only 50% arrggghh (much cursing)..........lol........

the first line of your post says


"the other job is to actually get the rotated cylinder coordinates. Maybe hybrid OpenGL way could be used, by retrieving current matrix at each pass of the generation and multiplying calculated vertices by that."

Is this regarding export to OBJ or is it about generating continous mesh ?

The continous mesh thing isnt the main goal at the moment i was just putting forward an idea as to how i might go about it.

I would rather be working towards getting export to OBJ done and working.

Petr Schreiber
13-03-2009, 15:59
Hi,

well, lets put it 51%, looks better :)

You need to get rotated cylinder coordinates for both.

What you do now:

- create new cylinder in slot 1
- transform it on HW
- render it on HW
- doing lot of times to render whole tree


What must be done for export:

- create new cylinder in slot 1
- get its coordinates, transform them on SW level, write somewhere
- doing lot of times to render whole tree


That means there are two main things to solve:
- how to transform correctly the vertices from local cylinder space to global space
- how to write the result to file

Part A is harder, part B is extremely easy on other side :)

I will investigate how to make the transformation on SW without much work, ahem :)


Petr

Macros The Black
13-03-2009, 16:56
I understand the basic principles of what you are saying but i dont really have a clue where to start.


create new cylinder in slot 1does this mean create the cylinder in a display list ?

If so, then do i dump the display list's transforms to file on each pass ?

Or am i wrong ? :?

Call me clueless.. :?..but i have made a lot of progress with the basics of TBGL and will keep working at it. 8)

Petr Schreiber
13-03-2009, 17:42
Hi Macros,



create new cylinder in slot 1

that means doing it as you do now, in m15 buffer.

So you now can get the cylinder coordinates as it was not positioned, rotated.
We need to find the way to postprocess the coordinates so transformation is "baked" to them.

I need to think about it more, there are multiple ways to do it and I am not yet sure how.


Petr

P.S. Going out, my PC mouse starts to be unusable ... fact is it has 10 years for sure :)

Macros The Black
16-03-2009, 14:38
Hi again
I found an older version of the tree generator and was wondering.

It seems to save the exact tree that is onscreen which would make me think that it stores the same information about transform as what i need to do.(otherwise the loaded tree would just be random)

Is the way this information saved what i need?
Could it be changed to write out to what would be OBJ format? eg xyz position of vertices and tex coords

I have posted the older script so anyone that has missed it can find it here as well

Macros The Black
16-03-2009, 14:56
sorry can get the script to upload
but i am sure you know which one i am talking about
it had tree generator and tree reader.

Michael Hartlef
16-03-2009, 15:08
Why can't you upload it?

Michael Clease
16-03-2009, 15:12
This post. http://community.thinbasic.com/index.php?topic=353.0

Macros The Black
16-03-2009, 15:25
wierd timeout errors
problem with my server
always happens

Petr Schreiber
16-03-2009, 15:39
Hi Macros,

the problem with this old script is that was my first try - so it creates monsters, not trees.

The information which is saved to file is something I called DNA at the time :)
It is not similar to OBJ at all - special symbols are "reflection" of some TBGL commands, like square brackets for TBGL_PushMatrix / TBGL_PopMatrix.

File is parsed character by character to reconstruct the geometry - but reading program needs to have decoder, as tree3d does not contain info on sizes or vertices, all is silently presumed to be default.


Petr

Macros The Black
17-03-2009, 13:15
Hi again
Just wondering if you have had any luck with OBJ export at all.
Been looking at and using thin edge and noticed that it can save out OBJ.
Are the routines used to save out form thinedge simalar to what i need to do?
Also didnt want to quote you on this but i am a bit lost with this export thing....


You can make M15 model using TBGL_m15* commands - have a look to help file. It is slightly different principle.

Then you can go through the vertices and generate OBJ file.

If you will manage to create correct tree model, I will show you how to go through M15 in memory and output OBJ to file.


I have managed to get the tree working and now i am needing help to get this OBJ export sorted.

Petr Schreiber
17-03-2009, 13:58
Hi Macros,

it is simple - once you have model represented using m15 structure, you can go through all vertices, and get the coordinates back using TBGL_m15GetVertex* and pass it to your custom saving routine.

The problem is, you now represent the tree using m15 model ( good ) positioned using lower level translate command ( bad ).

That is why I repeat you need to postprocess the model data with translation and rotation first, so no transforms are involved and you have pure, ready to go, vertex data.

ThinEdge saves OBJ without any trouble, as there is no transformation stack of scaling, rotating and shifting vertices. You have polygon coordinates, you export them.

Try following on your basic cylinder test, usage is like SaveM15AsOBJ("C:\Cylinder.obj", 1), it requieres use of FILE module:


SUB SaveM15AsOBJ( fName as string, modelSlot as long )
' -- This routine exports just geometry, no UVs or materials, yet

dim numVertices as long = tbgl_m15GetModelVertexCount(modelSlot)
dim i, stopFlag as long
dim x,y,z as double

' Minimal OBJ file for triangle would look like:
'# This is my OBJ file
'# Vertices
'v -1.000000 -1.000000 0.000000
'v 1.000000 -1.000000 0.000000
'v 0.000000 1.000000 0.000000
'# Faces
'f 1 2 3

dim objFileContents as string = "# This is my OBJ file"+$CRLF+"# Vertices"+$CRLF

' -- Going through all vertices
for i = 1 to numVertices
' -- Returned by reference
tbgl_m15GetVertexXYZ(modelSlot, i, x, y, z)
objFileContents += STRFORMAT$("v {1} {2} {3}"+$CRLF, x, y, z)
next

objFileContents += "# Faces"+$CRLF+"f "

' -- Second pass, detecting faces
for i = 1 to numVertices
' -- Last in poly or not?
stopFlag = tbgl_m15GetVertexPStop(modelSlot, i)
objFileContents += STRFORMAT$("{1} ", i)

' -- New face will be the next
if stopFlag = 1 and i <> numVertices then
objFileContents += $CRLF+"f "
end if

next
objFileContents += $CRLF

FILE_Save(fName, objFileContents)

END SUB



Petr

Macros The Black
17-03-2009, 16:34
Thanks for the script
I am testing it on the cylinder for the next few hours
It shows a lot of what i need to know.
Figuring out the translation for the vertices after tree generation is difficult
i have tried several things but nothing seems to work.(Or i am just trying the wrong approach)
Will keep on trying but i think that it is a bit beyond me.

Also about continous mesh generation.
In theory couldnt the transforms be applied at polygon/vertex level and then the data generated used to build trees.
For example,
define the base vertices(bottom only) of M15 cylinder.
Then apply the transforms to get the height, angle, twist, and radius for the next set of vertices.
Therefore generating a tree with continous mesh (this is just a theory,not sure if it would actually work)

If done this way the vertices would all be in one mesh and then it would be a simple export routine for one mesh.

Petr Schreiber
17-03-2009, 19:51
Hi Macros,

good thinking with the continuous mesh idea, but it has one problem - one cylinder branches to more, so it is little more difficult to make the joints look good.

But I think your idea with one mesh with all branches is good one - it would be much easier to export.
So maybe it is time to leave idea of 1 model 1 cylinder and make smooth move to the dangerous waters of one big mesh with all branches...

One of possible materials for study is Wikipedia article on Rotation matrix.


Petr

Macros The Black
18-03-2009, 03:40
I am looking into the continuos mesh idea at the moment but
keep getting confused(trying to get to far ahead of myself as usual)
So i am going back to the start to try and incorperate the continuos mesh idea.

The transforms should be similar to the ones already used but will be called on the vertices to make the tree.
the only thing is i am not so sure of how?
The joints of the branching is a minor issue(at the moment)

I think i will try to get the transforms of the vertices working first then worry about implementing a way to cleanly join them at the joints later.

I think the most difficult vertices to join will be the vertices that are directly involved in the branching (the ones that form the "Y" sections).
The sections in between that are just straight branches should be relatively easy to join.

Had another idea
What if the base mesh for the tree is defined as a square,then the transforms applied.
Upon reaching a joint the process of branching the mesh would be simpler(less points,no COS,SIN for radius needed)
Then once all transforms have been made, wouldnt it be possible to smooth out the tree's surface,
possibly using a meshsmooth type approach like in 3ds max, but an open gl/TBGL equivelant.
Do you think this is possible?
Sorry about using 3ds max terms but i didnt know how else to explain what i was thinking.

Petr Schreiber
18-03-2009, 08:49
Hi Macros,

you are right transforms of vertices must be done first.

Regarding your idea with cubes - not bad, but you will need SIN/COS anyway for the transforms.
And the smoothing algorithm can get difficult, as it needs to find which vertices are common ( share the same x,y,z ), then take action on it.

Regarding how to use rotation matrices - it is relatively simple.

- You create matrix 3x3 based on that Wikipedia formulas ( in place of cos(fi) you place calculated cosinus for given angle )
- You create matrix 3x1, filled with nothing else but x,y,z of one vertex
- You create matrix 3x1 where you store the result
- You save it back to the m15 mesh

Do you dislike math around matrix multiplication?
ThinBasic has matrix math built in, so the task will get as easy as:

MAT coordinatesResult() = rotationMatrix() * coordinatesXYZ()

If you want to understand it better, read first info on 2D transform here: http://mathworld.wolfram.com/RotationMatrix.html

... and then check this script:


USES "Console", "Math"

dim vector2(2, 1) as ext
dim vector2result(2, 1) as ext
dim rotationMatrix2D(2, 2) as ext


vector2(1,1) = 1
vector2(2,1) = 0

printl "Vector"
printl "======="
printl "| "+FORMAT$(vector2(1, 1), "#.000")+" |"
printl "| "+FORMAT$(vector2(2, 1), "#.000")+" |"

dim angle as double = DegToRad(90)

rotationMatrix2D(1, 1) = cos(angle), -sin(angle)
rotationMatrix2D(2, 1) = sin(angle), cos(angle)

printl
printl "Rotation matrix"
printl "================"
printl "| "+FORMAT$(rotationMatrix2D(1, 1), "#.000")+" "+FORMAT$(rotationMatrix2D(1, 2), "#.000")+" |"
printl "| "+FORMAT$(rotationMatrix2D(2, 1), "#.000")+" "+FORMAT$(rotationMatrix2D(2, 2), "#.000")+" |"

mat vector2result() = rotationMatrix2D() * vector2()

printl "Vector rotated by 90 degrees"
printl "============================="
printl "| "+FORMAT$(vector2result(1, 1), "#.000")+" |"
printl "| "+FORMAT$(vector2result(2, 1), "#.000")+" |"

waitkey


If you understand this, you are ready.


Petr

Macros The Black
18-03-2009, 15:04
Thanks for the tips Petr.
I am thinking that the smoothing and cube method sounds good but isnt really the best option.

Regarding "dislike math around matrix multiplication"
Never really thought about it like that.
Was just looking for an easy way....lol...

I do understand the script you posted, but understanding and knowing are two different things..
eg... i understand how a car works but ask me to build one and i wouldnt know how......lol...

I tried to make a start on continuos mesh idea but keep getting weird results so i have trashed the script and will start again.

What i am having trouble with is how to create the vertices while performing transforms at the same time
for example.......

create the only bottom of the cylinder M15,
then perform transforms to get position for next vertices,
now create second lot of vertices,
now perform the transforms again,
then perform transforms to get position for next vertices,
now create third lot of vertices and so on

Does this seem like the way it would be done?
Or have i got the order of things wrong?

--------------------------------------------------------------------------------------------------------
OBJ SAVE
--------------------------------------------------------------------------------------------------------
I am posting a newer version of the save script you posted.
It now uses Dialog_savefile and your save routine.
You can now name the OBJ file that is output.
Currently it only works with the M15 cylinder that i am using in the tree generator
as there is no load model feature. (i dont currently need it).
But it serves as a good example of how to output OBJ.

The new script includes the Save routine and the M15 cylinder.(2 useful scripts)
In most 3D apps it seems to work fine.

Some model viewers dont seem to like the output though.
With several showing that 2 faces are missing.
I think this is a issue with the model veiwers and not the OBJ file as it seems to work fine in
3ds max,Poser,Bryce 6,Daz Studio and a whole lot of other apps as well.
Anyway take a look and see what you think.

Petr Schreiber
18-03-2009, 16:07
Hi Macros,

yes yes yes! It is good to do transforms immediately.
To understand them, what about creating custom set of My_PushMatrix, My_PopMatrix, My_Rotate, My_Translate ?

OBJ "problems" you see are really at least partially thing of those programs, how do they see the data.
Lot of programs work with concept of "front face" and "back face".

How do they differentiate front from back? By order of vertices.
You can try it - reverse order of vertices of top and bottom part of cylinder, and you will see they'll suddenly become "visible".


Petr

Macros The Black
18-03-2009, 17:12
hi again

You said

To understand them, what about creating custom set of My_PushMatrix, My_PopMatrix, My_Rotate, My_Translate ?


Does this mean that i basically create custom functions for My_PushMatrix, My_PopMatrix, My_Rotate, My_Translate and then call them when creating vertices.
for example if i made these custom functions and called them at the right time this would work? (SEE CODE BELOW)


FOR i = 0 TO ( qualityStep - 1 )

My_PushMatrix,
TBGL_M15SETVERTEXXYZ( 1, vertexIndex, COS( i * angleJumpRad ) * radius, 0, SIN( i * angleJumpRad ) * radius )
TBGL_M15SETVERTEXTEXXY( 1, vertexindex, i, 0 )
TBGL_M15SETVERTEXRGB( 1, vertexindex, 255, 255, 255 )
My_PopMatrix,
My_PushMatrix,
My_Rotate, My_Translate
INCR vertexIndex
TBGL_M15SETVERTEXXYZ( 1, vertexIndex, COS( i * angleJumpRad ) * radiust, height, SIN( i * angleJumpRad ) * radiust )
TBGL_M15SETVERTEXTEXXY( 1, vertexindex, i, height )
TBGL_M15SETVERTEXRGB( 1, vertexindex, 255, 255, 255 )
My_PopMatrix,

This is just an example of what i thought would work
What do you think?
Is this what you meant?

The polygon problem isnt really an issue as it only happens in some model viewers.
All the applications i would be using the exported objects in work fine.(no problems at all)

I am making an assumption that the code used to get vertex data would also work to retrieve tex coords with a few minor changes.
I will try to get textures exporting by restructuring the code to handle tex coords as well as the geometry.

Petr Schreiber
18-03-2009, 17:38
Hi Macros,

not exactly like that, but nearly yes.

OpenGL uses one matrix, 4x4. It contains both information about translating, as well as rotation and scaling ( we do not use scaling here, so no need to care ).

My_* commands would simply modify the matrix like TBGL commands do.

So we would calculate cylinder coordinates like now, but before passing them to m15 we would multiply them by our "instant transform" matrix.


Petr

Macros The Black
19-03-2009, 04:57
Hi again
Thanks for the tips (again)
Just wondering if you could post an example of "instant transform" matrix?

I am just not that sure of what transforms to perform and where to perform them.

"before passing them to m15 we would multiply them by our "instant transform" matrix"
I am not really sure where to call the instant transform matrix.

Do all the transforms get scripted inside the new My_* commands and then called to manipulate vertices near the end of
the script that creates M15 vertices ?

Or are the transforms called in between the creation of each set of vertices ?

Would this process be replacing most of the drawbranch function?
or
would it all be happening inside the drawbranch function?

Sorry for all the questions i am just getting a bit confused as to how to perform these transforms and then create new vertices at the position and rotations defined by these transforms.

Petr Schreiber
19-03-2009, 08:02
Hi Macros,

I am sorry, I woke up too late - I must leave now, and I will be back by late night ( in central Europe ).
But to give you good material to study, here is very good article:
http://www.morrowland.com/apron/tutorials/gl/gl_matrix.php

I think this approach will maintain most of the code, just the assignment to vertex XYZ would become:
- calculate x,y,z and store it ro array
- multiply by transform matrix
- retrieve new coords and put them to tbgl_m15SetVertexXYZ

... might sound scary, but it isn't, you'll see.


Must go,
Petr

Macros The Black
19-03-2009, 16:13
I have tried to implement the approach you have described and cannot get it to work.
I have looked at the article you linked to and found it to be informative and helpful(but still i mess things up).
Anyway its late here and will im goin to bed

SEE NEXT POST

Macros The Black
20-03-2009, 17:04
Hi again
I am still trying to get the continous mesh working however..........
More Questions
1....The calculation of x,y,z and storing to an array is just positioning and rotation , NOT the vertices right?
2....The transforms in the drawbranch function are the transforms that i need to perform before vertex creation right?
3....Then i have to pass these transform to TBGL_M15SETVERTEXXYZ to create the new vertices in the right position and with
the correct rotations right?
4....Should everything be coded inside the drawbranch function?
Or
5....Should it be a few different functions that are called at the right time to perform transforms and vertex creation?

Implementing it is confusing the hell out of me.
So here i am pleading for even just the most simple example of what order i should be putting things in.
even just a small code demonstrating the right order would do i can work it out from there..

I understand i have to calculate the x,y,z positions before i create the vertices
I also understand that i have to perform the transforms before vertex creation as well
but every attempt i make just makes the tree app freeze up and not work at all.

I just cannot seem to get the order of things right in the code.

Once again i will offer my most humble apologies for being such a pain in the butt...and questioning you repeatedly on the same thing..

Petr Schreiber
20-03-2009, 18:51
Hi Macros,

no need for apologies!

1 - I am not sure I understand the statement ( I start to speak in error messages ), is the following answer for you?:
"x,y,z -> [ positioning, rotating ] -> modified x,y,z passed as vertex coordinates"

2 - yes

3 - in theory yes, in reality you can live with global transformation matrix

4 - I guess it is one of the ways + the function to render cylinder

5 - Also "yesable" question -> transform functions + drawBranch + createMesh + save result = job done

One thing - very busy weekend starts for me, so I probably won't have much time to study this problem -but- I will check out how to implement the transformations ( matrices and their stack + casting it on x,y,z ), so you do not have to be scared by this part of problem.


Petr

Macros The Black
22-03-2009, 08:38
Firstly i will say that i am not trying to start again on the tree generator with what i am proposing in this post.
I am just throwing an idea out there to get your thoughts on it..

I have been looking around the internet and found a script that creates a continuos mesh tree.(at least it looks that way in the screen shots)
Problem is it is a qbasic script and i am having a lot of trouble translating it to thinbasic & tbgl.

I am not expecting it too be easy to translate but i was just wondering if you could take a look at the script and see if you think this method can be translated into thinbasic/tbgl script...
Just a yes or no will be fine.....

However if you think this can be done and IF you want to try to implement this method then that would be great.

I know i have sort gone of track a bit with trying to convert this script to thinbasic/tbgl but it seems to go about things in a way that is able to generate single mesh trees..

Below are the links for the webpage that has the script and tutorials for qbasic

http://www.petesqbsite.com/sections/express/issue18/#treetut
http://www.petesqbsite.com/sections/express/issue18/tree_basicSkeleton.bas

Once again i am NOT trying to rewrite the tree generator from the start, I am just asking if you think we could make use of the methods used in the qbasic script to create continuos mesh..

If you think that the methods in the qbasic script are no good for thinbasic/tbgl then i will continue with trying to implement the continuos mesh using just tbgl commands and forget about converting the qbasic script..

Thanks again for any help

Petr Schreiber
22-03-2009, 09:21
Hi Macros,

this is very good article, I did not know about it earlier.
Answer to your question is yes - it can be very painless translation, once you keep an eye on these things:

- variable! means the same as using variable defined AS SINGLE
- variable% means the same as using variable defined AS INTEGER
- arrays in example use zero based arrays, while TB starts from one
- some variables in example are not defined using DIM syntax, you should do this yourself

... and just to make you sure we were converging to solution - mRotate, mScale are basically what I meant by My_Rotate, My_Scale transform functions.

I am short in time, I did not managed to do what I wanted, so I am not able to make translation of the code for you. But ... as the code is 98% compatible with TB, ... it should be no problem for you I think, take as base the tree_leaves code. It even uses custom pushMatrix, popMatrix.

Only thing which will differ is way to draw it.


Petr

P.S. I am not 100% sure the way they draw cylinders is what you want, as they are not true cylinders

Macros The Black
22-03-2009, 16:37
the tutorial has made one thing clear to me
Your original tree generation code is already set up to implement this approach..

I think that there are aspects of the qbasic script that could be useful in generating continuos mesh..
Especially the methods they use to generate the new vertices according to pre calculated positions/rotations..
I am pretty sure that chapter 3 contains all the code i would need to "borrow/translate to tbgl" to make this happen..

The only problem is how to incoorperate this into your original Tree Generator script without changing too much..

My reworking of your original tree generator script allows good levels of control over nearly all tree parameters including --radius, length,levels,openangle, and twist as well as LOD for the .M15 cylinders via the UI that i have made..

I know i would have to set things up a little differently to what i have done,but i would like to keep as close as possible
to the original script
In the end i should be able to keep the controls for most of the tree parameters...therefore allowing the parameters to be adjusted to make different trees.

So basically i have figured out that using this method i would

Use current Drawbranch function with %gl_lines instead of .M15 cylinder.... (these %gl_lines would not be rendered)

Incoorperate the node method used in the qbasic script into the drawbranch function to get the positions/rotations...

Create new function that will create new .M15 vertices based on node positions/rotations..

Somehow create continuos mesh with the new .M15 vertices..

What do you think?
Am i on the right track?

I am not sure if you checked out the whole tutorial...parts 1-6...
I have attached the Qbasic tutorials and files in zip format so that anyone who wants to have a look at the Qbasic tutorials and script doesnt have to go searching...(this zip is just the final project files as well as tutorial parts 1-6)..

Petr Schreiber
22-03-2009, 17:10
Macros,

thank you, I saw just part 3-4.
I will check out 1-6, but not sure when, as I am getting crazy with school and work now, it might be as late as next weekend.

From quick look it seems they use OpenGL transforms only for leafs, which is not that important at the moment.


I am sorry,
Petr

Macros The Black
22-03-2009, 17:47
No rush
i need to learn for myself how to get this done and i think the tutorials will be the key.

Its just a matter of figuring out how to implement the nodes and then convert the coords and create vertices

most of the code is already there in the tutorials i just have to translate to tbgl and try and implement it without changing the
original tree generator script too much...

I want to keep my UI with the parameter controls so that all controls i have linked already will still control the same tree parameters and make it easy to change radius, length,levels,openangle, and twist as well as LOD for the .M15

It shouldnt take me that long as my understanding of tbgl is increasing all the time...

I will post my results when i get it working properly

I am going to try and keep the leaves as .M15 as well so they can also easily be exported.....Could be difficult but if i create the leaves using the same methods as for the branches i should end up with 1 mesh containing all the leaves.....Then i just have to work out how to assign textures to the individual leaves....This part could be hard though i am not sure as i havent looked into it at all....

Macros The Black
25-03-2009, 09:03
I think i might just give up!!

I was hoping to finish this project but i cannot see it happening...theres just to much that just will not work...(or i cant get it to work)

I am not trying to be negative i am just writing about what is going on with the scripts...

i have tried so many different approaches and cannot get the continuos mesh working....

I have no idea what to do about the continuos mesh as i cannot seem to get the code in the right order to work.
I have tried to implement some of the methods used in the tutorials i posted... like the nodes they have used to get positions/rotations for new vertices but i just ended up making a mess of the script and having to revert back to previous script with .M15 cylinder...

The tree generator works well....
Apart from a minor issue with the last M15 cylinder on each branch not working properly...
The textures on the last cylinder arent working and the last cylinder is black and something wierd is happening with the transforms on the last cylinder on each branch as well..

The UI is linked and all parameters can be adjusted to allow good control over radius, length,levels,openangle, and twist as well as LOD for the .M15 ( This is the only thing that does work properly)

I have also tried to get the exporter to export more than 1 model ( at the moment just 1 M15 cylinder and 1 M15 leaf)
and it wont happen...the code seems right but then it will only export the M15 leaf model correctly while the M15 cylinder ends up with all vertices at 0,0,0...dunno why....

But this is where i am stuck and cannot seem to progress any further...
The only training/education i have in opengl/tbgl is what i read online and what i have learnt from asking questions...
There is nowhere else i can get help because most of (not all) the info i need is tbgl specific and what i have read in the help files covers less than half of the things i am trying to do....

I will keep trying, but my time is getting severly limited as i have had to go back to work this week and will not really have much time off for several months...

thanks for all the help you have given me in trying to get this project completed...but i think i may have to scrap it...

Petr Schreiber
25-03-2009, 09:48
Macros,

come on!

You picked up one of the complex tasks, but sure it has solution. Giving up now ... imagine how many hours you dedicated to it already, that would be big loss...

The good feeling from finished project is worth little suffering :)

Also, you listed some problems in the posts above - but we cannot help you if you do not post code where it is happening.
Make little examples demonstrating each of the problems, and I will have look at it during the weekend as I said.

If you feel you are converting code not knowing what it does exactly, it is time to turn off PC, take pencil and paper, and try to specify what you need to achieve.


Petr

Michael Hartlef
25-03-2009, 11:25
Before I dig through all these posts, can someone explain to me in some short notes where Macros is stucked now?

Macros The Black
25-03-2009, 13:35
yeah sorry about last post......
just let things get the better of after really bad day...

the script i have been using is posted below with the UI , obj export script is also included...
i still have to fix one thing in the Ui and that is getting the camera to rotate around the tree instead of turning the viewport upside down (easy to fix just havent done it yet)
This is a clean version that has none of my mistakes in regards to the continuos mesh in it but thought i should post it anyways to show where i am at...

I have also incorperated a savefile routine to save .tree file......This is just the current settings for tree parameters and they cannot be reloaded yet

Quick overview of this scripts current problems

1... .M15 cylinders at the end of each branch lose their textures..

2... .M15 cylinders at the end(tip) of each branch are not transformed properly and can be larger than the previous branch...
to see what i mean just turn size up to more than 5

3... .M15 cylinders at the end of each branch are black....

--------------------------------------------------------------------------------------------------------------------------------

I tried to make the OBJ export script export more than 1 model ( at the moment just 1 M15 cylinder and 1 M15 leaf)
and it wont happen...the code seemed right but then it would only export the M15 leaf model correctly while the M15 cylinder ends up with all vertices at 0,0,0...

All code for the exporter has been reverted back to just exporting model 1....which in turn just exports one tip of one branch....
the code is basically Petrs object export script that was posted earlier....but just written into Tree generator so it can be used later on....Its was just in there as a test.....
Once i have worked out how to make a continuos mesh tree (one mesh for all branches) i will use it to export the tree as it will be one model...
The leaves will be exported as well
below is the basics....
tree = model 1
leaves = model 2
Export both as 1 .OBJ file

Anyway i hope theres something useful in this script for anyone that downloads it

Petr Schreiber
27-03-2009, 22:41
Hi,

1), 3) have the same reason - the way normals are smoothed.

That odd last branchpart has zero top radius, so while using smooth normals, it tries to find common normal for all vertices of the top, which are so different it causes this artefact.

To prevent this, just add following on top of Cyl procedure body:


if radiust = 0 then radiust = 0.001


2) - probably typo, just change:


IF i = 1 THEN
DrawBranch( radiusS, length, levels -1, - openangle, twist )
ELSE
DrawBranch( radiusE, length, levels - i, openangle, twist )
END IF


to


IF i = 1 THEN
DrawBranch( radiusE, length, levels -1, - openangle, twist )
ELSE
DrawBranch( radiusE, length, levels - i, openangle, twist )
END IF



For i = 1 bad radius was supplied, causing ugly endings.


Petr

Petr Schreiber
28-03-2009, 15:42
Macros,

as I promised, I had a look into the problematics of transformations and baking them to coordinate data.
It is even simplier approach than using m15 models. Please see it here: http://community.thinbasic.com/index.php?topic=2565.msg19191#msg19191

It should answer all of your questions ( continuous mesh generation I leave as excercise for you :) )


Petr

Macros The Black
29-03-2009, 12:42
Thanks for the example script....
This has shown me what i need to do and i have begun on continuos mesh...
one question though
Can the vertex data generated with tbTriangleBuffer_AddVertex
be exported to OBJ using save routine?

Anyway with the continuos mesh i am starting with just getting one branch continuos and then when its working i will move on to the rest of the branches...

The script ive posted is my current attempt at continuos mesh branch

the script isnt finished by far and the polys dont show up right ...

Also the vertices that are created stay and i cant figure out how to clear the buffer to redraw 1 new tree and remove the previous tree..

however i would ask you to look at this and tell me if you think what i am doing might work

Petr Schreiber
29-03-2009, 15:02
Macros,

yes, it is possible to export OBJ from the data, that was the purpose of whole example - all transforms baked in.
To acces triangle data, just get how many vertices using tbTriangleBuffer_GetCount() * 3, and then simply access the coordinates using tbVertices(i).x, tbVertices(i).y, tbVertices(i).z ...

Please re-download lib_TriangleBuffer.tbasic from here (http://community.thinbasic.com/index.php?topic=2565.0), I simplified clearing.

One thing - please, indent your code and keep it indented. Some of your procedures look like after gas boiler explosion, very hard to read :) Code like this:


IF i = 1 THEN


TBGL_PUSHMATRIX
tbTriangleBuffer_Translate 0, length, 0
tbTriangleBuffer_Rotate openangle, 0, 0,0.5
tbTriangleBuffer_Rotate twist, 0, 1, 0
tbTriangleBuffer_Rotate - openangle * 2, 0, 0, 3

ELSE

tbTriangleBuffer_Translate 0, length, 0
tbTriangleBuffer_Rotate openangle, 0, 0,0.5
tbTriangleBuffer_Rotate twist, 0, 1, 0

TBGL_PUSHMATRIX

tbTriangleBuffer_Rotate - openangle * 2, 0, 0, 3

END IF

TBGL_POPMATRIX
radiusS = radiusE
radiusE = radiusS - startRadius / levels
length = length - startlength / levels

NEXT
TBGL_POPMATRIX

... is hell to debug.

The converted version looks like:


tbTriangleBuffer_PushTransform()
FOR i = 1 TO levels
triangleBasedCylinder(qualitystep,radiusS,radiusE,length)

tbTriangleBuffer_TRANSLATE (0, length - 0.5, 0)
tbTriangleBuffer_ROTATE (openangle, 0, 0,0.5)
tbTriangleBuffer_ROTATE (twist, 0, 1, 0)

tbTriangleBuffer_PushTransform()
tbTriangleBuffer_ROTATE (-openangle * 2, 0, 0, 3)

IF i = 1 THEN
DrawBranch( radiusE, length, levels -1, - openangle, twist )
ELSE
DrawBranch( radiusE, length, levels - i, openangle, twist )
END IF
tbTriangleBuffer_PopTransform()
radiusS = radiusE
radiusE = radiusS - startRadius / levels
length = length - startlength / levels
NEXT

tbTriangleBuffer_PopTransform()

... indenting keeps track of transforms as you can see.

You also started to hardwire cylinder code inside draw branch - more modular code, more maintainable, so I returned back with cylinder rendering separate.

Complete code attached ( ! do not forget new lib_TriangleBuffer ! )

To add normals and tex coords, you should mod the triangle buffer code. Busy week starts for me so I will not be able to put my fingers on it till next weekend in ideal case. Good luck, the objective is almost complete!


Petr

Macros The Black
30-03-2009, 09:27
Thankyou!!Thankyou!!Thankyou!!
this is exactly what i was aiming to do....
The next step is texture's and then getting OBJ export working
Shouldn't be too difficult.....lol...

Would i just be making a texture function similar to the tbTriangleBuffer_AddVertex function ?
or
Would i be adding texture coords inside the tbTriangleBuffer_AddVertex function ?

and finally

Would i then use TBGL_BINDTEXTURE in the triangleBasedCylinder function to assign texture ?

Do you think this is the right sort of approach to texturing


sub tbTriangleBuffer_Render( drawAxes as long )

' -- Axis fork
if drawAxes then
tbgl_BeginPoly %GL_LINES
' -- X axis
tbgl_Color 255, 0, 0
tbgl_TexCoord2D tbTransform(1, 4), tbTransform(2, 4)
tbgl_Vertex tbTransform(1, 4), tbTransform(2, 4), tbTransform(3, 4)
tbgl_TexCoord2D tbTransform(1, 4)+tbTransform(1, 1), tbTransform(2, 4)+tbTransform(2, 1)
tbgl_Vertex tbTransform(1, 4)+tbTransform(1, 1), tbTransform(2, 4)+tbTransform(2, 1), tbTransform(3, 4)+tbTransform(3, 1)

' -- Y axis
tbgl_Color 0, 255, 0
tbgl_TexCoord2D tbTransform(1, 4), tbTransform(2, 4)
tbgl_Vertex tbTransform(1, 4), tbTransform(2, 4), tbTransform(3, 4)
tbgl_TexCoord2D tbTransform(1, 4)+tbTransform(1, 2), tbTransform(2, 4)+tbTransform(2, 2)
tbgl_Vertex tbTransform(1, 4)+tbTransform(1, 2), tbTransform(2, 4)+tbTransform(2, 2), tbTransform(3, 4)+tbTransform(3, 2)

' -- Z axis
tbgl_Color 0, 0, 255
tbgl_TexCoord2D tbTransform(1, 4), tbTransform(2, 4)
tbgl_Vertex tbTransform(1, 4), tbTransform(2, 4), tbTransform(3, 4)
tbgl_TexCoord2D tbTransform(1, 4)+tbTransform(1, 3), tbTransform(2, 4)+tbTransform(2, 3)
tbgl_Vertex tbTransform(1, 4)+tbTransform(1, 3), tbTransform(2, 4)+tbTransform(2, 3), tbTransform(3, 4)+tbTransform(3, 3)

tbgl_EndPoly
end if

Petr Schreiber
30-03-2009, 16:18
Hi Macros,

you need to do following:
- in tbTriangleBuffer_Init add TYPE and array for storage of UV coordinates
- in tbTriangleBuffer_AddVertex you might consider adding 2 new parameters for UV
- in tbTriangleBuffer_Render you should use glEnableClientState with %GL_TEXTURE_COORD_ARRAY and pointer to UV array

I am not sure if it is evident from the code, but you don't need no TBGL_TexCoord2D - the code you posted uses immediate mode which I used just for axisfork, not the mesh itself. So ... no,for this part.

The model is rendered from the arrays - it cannot be more elegant ( credit goes to OpenGL designers ).
You have array with XYZ and RGB, and you just pass pointer to it. No draw commands, no m15 models, just raw data passing.

Tree would have to be divided in two meshes - one with bark, second with leaves. Might sound odd, but it is the best for real time performance.
I would recommend to forget leaves for now, make complete tree with bark texture and export it, then you will see adding leaves is easy.


Petr

Macros The Black
01-04-2009, 11:28
hi again
i have had a go at getting the textures working and this is what i have come up with

The modified version of lib_TriangleBuffer and Cmeshtree(3) are posted below as TEX TREE.zip

i have added to sub tbTriangleBuffer_AddVertex( r as single, g as single, b as single, x as single, y as single, z as single , U as single, V as single)...
last two parameters for texture coords...
see both the scripts to see what i have tried..
I am not really happy with it at the moment as i think the textures arent really working right..they seem to use global coords and not local coords on the cylinders...
Any suggestions welcome

Petr Schreiber
01-04-2009, 21:14
Macros,

<terrible joke>you are cutting branch you are sitting on</terrible joke>

First you enhance tbTriangleBuffer_AddVertex to have U and V parameters:

sub tbTriangleBuffer_AddVertex( r as single, g as single, b as single, x as single, y as single, z as single , U as single, V as single)

... and then, in the code, you completely ignore them by using:


tbUVcoords(tbVerticesID).U = Result(1, 1)
tbUVcoords(tbVerticesID).V = Result(2, 1)


;)

One wish from my side - the last ZIP you posted is cannot be run without renaming files, then when I finally try to examine it it fails because I have no 12 leaves textures in TGA. Could you please keep just one single ZIP file, containing ALL files needed to run the script ( textures, properly named files ) in the first post of this thread with the most recent version?


Petr

Macros The Black
11-04-2009, 08:21
Hi again


First you enhance tbTriangleBuffer_AddVertex to have U and V parameters:


sub tbTriangleBuffer_AddVertex( r as single, g as single, b as single, x as single, y as single, z as single , U as single, V as single)

... and then, in the code, you completely ignore them by using:

tbUVcoords(tbVerticesID).U = Result(1, 1)
tbUVcoords(tbVerticesID).V = Result(2, 1)



Yeah i figured that out after posting....
Sorry about the bad zip organization.....i zipped the wrong file so all includes and script had not been changed.....
Anyway here's my latest with the attempt at continuos mesh....

I have seperated things into seperate files and now things are easier to handle....
all files are included in zip....
No textures needed as they are not used at the moment....
Also left out some things that arent required to generate a branch....

I have stopped trying to make the whole tree and i am concentrating on just getting one branch working as a continuos mesh.
I think that completing this step is the starting point to the whole tree but for now i need to just get the one branch working..

The script i am posting below is not a functional version of the tree generator....
It is my poor attempt at generating one branch from a series of nodes...

There are several problems with this script....Just to say its not pretty...lol... :lol:
It does look odd but at you should at least change some paremeters and generate a few branches to see that it does at least try to work...
Changing the levels and the LOD has the most effect but with unpredictable results..... :comp1:
The transforms like rotations and translations work fine....
I will not go into details here as i have commented the script to outline the rundown of what i aim to do and the problems :evil5: i am having....
:sick32:My brain is overloaded from reading :read: so many open gl tutorials and references in the last week that i need a break for a bit.....

As always any help would be great.....

Petr Schreiber
11-04-2009, 12:25
Hi Macros,

I must say it was pleasant surprise for me - your code is divided to smaller fragments, much more commented than previous versions :comp4:.

The main problem of your current approach was little oversight. Triangle buffer is composed from triangles(3 vertex), you tried to create quads(4 vertex). You also, somehow, created some vertices twice, so instead of 20 points you generated 30.

To catch such a things, I recommend binding Console module and printing some info there.

I attach working version for you, the face color might look little odd, but that is because of absent normals and lighting used.


Have a nice weekend and good luck with further developement!,
Petr

ErosOlmi
11-04-2009, 12:51
Macros,

very very nice UI.
I just adjusted TRACKBARS size (10 is too small while for me 15 is perfect) and avoid to not have ticks (%tbs_noticks style).
Thanks a lot for your effort that showed me once again we are on the right track with thinBasic.

Ciao
Eros

Macros The Black
16-04-2009, 16:40
Hi again
firstly thanks for the kind words Eros, its good to get some feedback....

Also thanks to Petr for the modification of this script to get a continuos mesh branch working...


The script i am posting is just to show what i have been attempting to do recently...
The script is commented to save me writing to much in this post...

One suggestion i have is that if anyone modifies or edits this or any other script....
That they would comment what they have done and how it works...
This way other people can learn as they go by referencing the comments provided in the edited scripts.....

And sorry about the larger zip but using large texture for leaves.....

Petr Schreiber
17-04-2009, 07:06
Hi Macros,

I will check the code during the weekend.
Just from quick look - glNormal3f is used in immediate mode, not in vertex arrays. In VA you have to create array of normals (similar to array of coordinates, colors, ...) and pass values from there.

Petr Schreiber
19-04-2009, 13:55
Hi,

I do not have much free time this weekend, so just UVs fixed in attached sources :?
Google for normal calculations, you will see it involves simple operation on 2 vectors, extracted from triangle...


Petr

Macros The Black
21-04-2009, 02:44
****************************POST HAS BEEN UPDATED*****************************

I have managed to get the normals working on the both the 2d and 3d versions of tree generator so thats no longer a problem....
Changed to 2d for something different....Not replacing 3d but just trying something...

Now trying to get continuos mesh working.....got ideas but not sure how to implement them....or if they will work....

Also working on the 2d version of tree generator,Updating the way branches are drawn and adding leaves....
Also trying to find a way to get a good quality rendered image out of the 2d or 3d tree generator for use with billboards
in large scenes..

Only have a quick question in regards to rendering higher quality images

Is it possible to render out images in the same manner as apps like 3ds max,Bryce,Maya,Poser...etc....etc ?

What i mean is render an image that can be saved to file formats like tga or png with transperancy...

Would i need a 3rd party render engine or can this be done in tbgl/thinbasic ?

Petr Schreiber
24-04-2009, 16:54
Hi Macros,

I am not sure what do you mean by "good quality image" - I think that is rating which differs from person to person :)

To your "quick question" there can be pretty long reply - it all depends on what do you want.

In case you are eager to learn new stuff, you want to understand all the mechanics of simulating materials, lighting etc. on PC, you need total control over what you do ... then I would recommend starting learning shading language ( ThinBasic supports GLSL and CG currently ). Please be warned it is run on the long track ( but in my opinion worth the time ).

If you just want to get the job done fast, then you can start studying some raytracers ( and their input fileformats), like YafRay and POV-Ray. They do a lot of work for, of course they cannot be used for real time rendering.

But the most important thing lies aside of technology - in case you plan to create commercial software, I would recommend to study trees in more detail, from "biologist" point of view. That will give you the best results with true "look and feel" of trees, that makes difference.

Along with custom textures ( even took by digital camera ) - nothing is more sad that watching new 3D RPG games having the trees looking all the same.

I still do not know for what do you need to generate trees - maybe purchasing license of SpeedTree (http://www.speedtree.com/) can save you some work - with the risk trees used in your project will look oddly similar to trees in projects of others.

There is nice gallery on speed tree website with some nice billboard like images (http://www.speedtree.com/trees/). Maybe good inspiration for your project.


Petr

Macros The Black
24-04-2009, 18:03
Hi again

By good quality image i mean a non realtime rendered anti-aliased image like the image output from applications like pov-ray...
I would like to be able to output images from a tbgl/thinbasic application that are higher quality than what you see in the viewport in realtime...
For example render image out at 2048 x 2048 and be able to save it to tga image format with transperancy...

I use billboards and 3d models in backgrounds of 3d scenes created in a number of high end 3d applications...
My main aim is to use the trees from Tree generator as either 3d models or Tga billboards....Both are needed..

The development of a commercial application is a fair way off at the moment because their is far to many things
to learn and features to include....

At the moment i am struggling with the continuos mesh idea and not really getting anywhere..
I cannot figure out how to implement it...

I was thinking if all the nodes for both a single branch and the whole tree were transformed first, It would then just be a matter of using the same method being used already to add vertices and figuring out what order to draw them in..
However i cant get this working despite many attempts....

Do you think continuos mesh is possible using the script as it is currently..or...would the script need to be completely rewritten to be able to achieve continuos mesh...

I only ask because i have tried to figure out how to do this but keep going around in circles...
No script to post as nothing has really changed in the generation part of the script....apart from the normals are working now...