CreateTree() Problems

Blitz3D Forums/Blitz3D Programming/CreateTree() Problems

asdfasdf(Posted 2004) [#1]
I'm trying to make a simple tree function that will make a tree shape like and X. Here is the code. I don't think it works.
Function CreateTree(file$,width#,Height)

tree = CreateMesh()

surf1 = CreateSurface(tree)
surf2 = CreateSurface(tree)

v0 = AddVertex(surf1,-1.0,-1.0,0)
v1 = AddVertex(surf1,1.0,-1.0,0)
v2 = AddVertex(surf1,1.0,1.0,0)
v3 = AddVertex(surf1,-1.0,1.0,0)

tri0 = AddTriangle(surf1,v0,v1,v2)
tri1 = AddTriangle(surf1,v0,v2,v3)

v4 = AddVertex(surf2,-1.0,-1.0,0)
v5 = AddVertex(surf2,1.0,-1.0,0)
v6 = AddVertex(surf2,1.0,1.0,0)
v7 = AddVertex(surf2,-1.0,1.0,0)

tri2 = AddTriangle(surf2,v0,v1,v2)
tri3 = AddTriangle(surf2,v0,v2,v3)

tex = LoadTexture(file$)

EntityTexture tree,tex

FreeTexture tex

Return tree

End Function



jfk EO-11110(Posted 2004) [#2]
Maybe try this:

Function CreateTree(file$,width#,Height)

tree = CreateMesh()

surf1 = CreateSurface(tree)

v0 = AddVertex(surf1,-1.0,-1.0,0,0,0)
v1 = AddVertex(surf1,1.0,-1.0,0,1,0)
v2 = AddVertex(surf1,1.0,1.0,0,1,0)
v3 = AddVertex(surf1,-1.0,1.0,0,0,1)

tri0 = AddTriangle(surf1,v0,v1,v2)
tri1 = AddTriangle(surf1,v0,v2,v3)

v4 = AddVertex(surf1,-1.0,0,-1.0,0,0)
v5 = AddVertex(surf1,1.0,0,-1.0,1,0)
v6 = AddVertex(surf1,1.0,0,1.0,1,1)
v7 = AddVertex(surf1,-1.0,0,1.0,0,1)

tri2 = AddTriangle(surf1,v4,v5,v6)
tri3 = AddTriangle(surf1,v4,v6,v7)

updatenormals tree
tex = Loadbrush(file$,4) ; using masked flag (4)
paintmesh tree,tex
entityfx tree,16 ; make visible from both sides
Return tree

End Function



This should create 2 crossed Quads that are visible from both sides. The texture uses the mask flag, this means all black pixels are transparent. So you'd need to use a texture that contains a tree image with black background.

No need for seperate surfaces as long as they use the same brush or texture. Added UV Coods to the AddVertex Commands.

I didn't test it, but it probably works. :)


asdfasdf(Posted 2004) [#3]
I would call like this right:
tree = CreateTree("Tree.png",10,20)
PositionEntity tree,0,0,0

Does the size work because it doesn't like you are useing the width and height parameters. How would I use them?