Posted: 12th Feb 2014 19:40
This snippet allows you to draw 2D lines which represent extrusions of a vertically segmented column.
The program will then render the actual (symmetrical) 3D column from your 2D layout.

NOTE: To get a clean object with this early version it's advised to add lines from TOP to BOTTOM only.
However, starting a line where the previous one was seems to look alright.


+ Code Snippet
Dummy=900:make object cylinder Dummy,1:hide object Dummy
Orange = rgb(200,100,0)
White=rgb(180,200,180)
Green=rgb(0,200,0)

HalfW=screen width()/2
HalfH=screen height()/2
backdrop on:color backdrop rgb(42,62,35)
dim x(10000)  `dim x(10000)
dim y(10000)  `dim y(10000)

x(1)=screen width()*.4:y(1)=screen height()*.15


Selected=1
ReStart:
if Main>0 then delete object Main
do
if mousex()>=HalfW then position mouse HalfW,mousey()
gosub 2dRender
if EditMode=1 then if returnkey() or mouseclick()=1 then goto ModeJump
if EditMode=0 and lower$(inkey$())="a" then inc AddMode:if AddMode=1 then inc Linecount:Selected=LineCount:x(Selected)=mousex():y(Selected)=mouseY():EditMode=1
if AddMode=2
AddMode=0
x(Selected)=mousex():y(Selected)=mouseY()
ENDIF


if lower$(inkey$())="d" then x(Selected)=0:y(Selected)=0:Selected=LineCount-1
if lower$(inkey$())="r" then goto 3dRender
if lower$(inkey$())="e" and AddMode=0 then inc EditMode:position mouse x(Selected),y(Selected)

if EditMode=2
ModeJump:    
EditMode=0:AddMode=0
x(Selected)=mousex():y(Selected)=mouseY()
ENDIF

while inkey$()<>""
gosub 2DRender
ENDWHILE

if scancode()=15 then inc Selected:if Selected>LineCount then Selected=1
while scancode()=15: Gosub 2dRender:ENDWHILE
LOOP

`RENDER in 3D
3dRender:
Main=9000
make mesh from object Dummy,Dummy
make object plain Main,0,0

for L=1 to (LineCount-1)
add limb Main,L,Dummy
lock vertexdata for limb Main,L
for v=0 to get vertexdata vertex count()
xx#=get vertexdata position x(v)
yy#=get vertexdata position y(v)
zz#=get vertexdata position z(v)
position object Dummy,0,yy#,0
point object Dummy,xx#,yy#,zz#

if yy#>0
xFinal#=HalfW-x(L)
move object Dummy,abs(xFinal#*1)
xx#=object position x(Dummy):zz#=object position z(Dummy)    
set vertexdata position v,xx#,(-y(L)*1)+HalfH,zz#    
ENDIF

if yy#<0
xFinal#=HalfW-x(L+1)
move object Dummy,abs(xFinal#*1)
xx#=object position x(Dummy):zz#=object position z(Dummy)    
set vertexdata position v,xx#,(-y(L+1)*1)+HalfH,zz#    
ENDIF


next    
unlock vertexdata
NEXT

scale object Main,10,10,10
make mesh from object Main,Main
delete object Main
Make object Main,Main,0
set object cull Main,0

do
if lower$(inkey$())="q" then goto ReStart
if inkey$()="s"
f$="aaa_NewColumn.dbo"
if file exist(f$) then delete file f$
save object f$,Main:end
ENDIF
control camera using arrowkeys 0,.1,.1
set cursor 0,0
print "[Q]=Return to Editor"
print
print "[S]=Save as 'aaa_NewColumn.dbo'"
LOOP

2dRender:
LineCount=0
for n=1 to 1000
if Selected=n then ink Orange,0 else ink White,0
if Selected=n and EditMode=1 then ink Green,0
if x(n)<>0 then LineCount=n
if x(n)<>0 and EditMode=0 then line x(n),y(n),(HalfW)+(HalfW-x(n)),y(n)
if n<>Selected and EditMode=1 then line x(n),y(n),(HalfW)+(HalfW-x(n)),y(n)
if n=Selected and EditMode=1 then line mousex(),mousey(),(HalfW)+(HalfW-mousex()),mousey():LineCount=n
next
if EditMode=1 then ink green,0 else ink White,0

set cursor 0,0:print "[TAB] Selected: ";Selected;"/";LineCount
print
print "[E]dit Selected Line"
print
print "[A]dd a Line"
print
print "[D]elete Selected Line"
print
print "[R]ender Column"
print
set cursor 0,400:print mousex();",";mousey()
return


Feel free to revamp this code into something better!
Posted: 13th Feb 2014 22:52
Though I can't really give you any points for code structure, it's still a neat program.

NOTE: To get a clean object with this early version it's advised to add lines from TOP to BOTTOM only.

What you can do is sort your lines by Y-coordinate before rendering the column
Posted: 14th Feb 2014 0:44
Though I can't really give you any points for code structure, it's still a neat program.


That's the nicest thing any Silver Codemaster has ever said to me.

Sadly, code structure is usually the last thing on my agenda.. sometimes I will restructure an entire program at the very end of development (on the rare occasion I actually finish something.)

What you can do is sort your lines by Y-coordinate before rendering the column.


LoL... now that you mention it, that would only take about 4-5 lines of code, huh? I'll definitely add that later this evening or tomorrow.

Also, I wanted to be able to close the very top of the cylinder, and drawing a line length of zero was an issue, so I did a test using the line if L>1 then move object Dummy,abs(xFinal#*1) to keep the top closed. This was in the "if yy#>0" section.. to close the bottom we can do if L<LineCount-1 then... in the other section.
Posted: 14th Feb 2014 10:57
Hi there.
@ Derek Darkly
I like it !!, that remember me when I start making my Dbpro Lathe Tool. It's a great code with just a few lines


Posted: 14th Feb 2014 16:25
I like it !!, that remember me when I start making my Dbpro Lathe Tool. It's a great code with just a few lines


Thanks Chafari - I feel like I am still just a beginner, but it's fun to learn.

Here's a pawn I made by pasting a silhouette image into the program and drawing lines over it. Then I texture painted in Blender:

Posted: 14th Feb 2014 19:50
You have improved your program a lot , that looks better and better , Now it really looks like a chess pawn
Posted: 14th Feb 2014 21:23
Thanks Chafari... I was watching Blender tutorial last night when it occurred to me that I could paste images into the program and draw lines over it. Easy-Peasy!

Posted: 14th Feb 2014 22:30
Yes, most 3D programs use to load a background image as a reference. You can implement your program, adding the ability of refine the model at runtime.



http://www.youtube.com/watch?v=rGNMtmAPMHY
Posted: 15th Feb 2014 0:51
Awesome, Chafari!
Your on-the-fly editor looks way more user-friendly than mine.

Do you have it available somewhere in the forums?
Posted: 15th Feb 2014 10:37
Thanks Derek Darkly. My first attempt to do a lathe was in 15th Nov 2011 . I made some poor tests .You can download the program here.

http://forum.thegamecreators.com/?m=forum_view&t=191389&b=1
Posted: 15th Feb 2014 16:11
Thank you again!

Great application - if I knew about this before I could have saved some time, but now this gives me another idea for an automated version!
Posted: 15th Feb 2014 19:59
if I knew about this before I could have saved some time, but now this gives me another idea for an automated version!


I suppose you have found the same problems I did. The bigest challenge for me, was to give a correct UV to the model. Now that you have learned to work with vertexdata, you have half the way done.

Cheers.
Posted: 15th Feb 2014 20:01
Any control over how many segments it makes around when building the object?
Posted: 15th Feb 2014 20:30
Any control over how many segments it makes around when building the object?


Exactly !!. we don't know the user inputs, so we have to wait until know how many entries make the user, then we have to divide the texture as many entries and scroll texture the same division.

BTW did you know that with this program we can make pipes?