3D library

Are you developing tools to extend the LiveCode environment? This is the place to talk about the nuts and bolts of extending our nuts and bolts. If you want to use a LiveCode or third party Environment extension, visit the Using Evironment Extensions forum.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

3D library

Post by MaxV » Mon May 19, 2014 12:07 pm

Hello,
I'm converting to Livecode a 3D library that I used on another programming language. I want to release it under GPL.
I'm working on arrays, a lot of arrays, so I need some trick to reduce the line to write.
For example I wrote this:

function r3d_translate x,y,z
#Create a translation matrix:
#1 0 0 X
#0 1 0 Y
#0 0 1 Z
#0 0 0 1
repeat with i=1 to 4
repeat with j=1 to 4
if i = j then
put 1 into temp[j]
else
put 0 into temp[j]
end if
end repeat
end repeat
put x into temp[1][4]
put y into temp[2][4]
put z into temp[3][4]
return temp
end r3d_translate

Is there a better solution or more elegant solution to write it?
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: 3D library

Post by MaxV » Tue May 20, 2014 5:09 pm

I'm working on the conversion of this old libray, it doesn't use OpenGL, just flat 2D polygons.
I already converted all matrix functions needed, now I need more information about creating a 2D drawing in Livecode.
Where I can found these information?
This is my goal:
Image
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: 3D library

Post by malte » Wed May 21, 2014 7:34 am

What kind of information are you looking for?

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: 3D library

Post by MaxV » Wed May 21, 2014 9:19 am

Hi malte,
I noticed that Livecode permit to draw using the "paint tools". I need to know how to create and specify the vertexes (x,y) of a polygon.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: 3D library

Post by malte » Wed May 21, 2014 12:04 pm

Hi, you might be way better off using the graphic primitive. Using the paint tools will be much slower.

Best,

Malte

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3255
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 3D library

Post by bn » Wed May 21, 2014 1:24 pm

Hi Max,

have a look at this thread

http://forums.runrev.com/viewtopic.php?f=9&t=7824

last stack is a sort of pseudo 3D made with graphic objects

or this thread

http://forums.runrev.com/viewtopic.php?f=9&t=13399

Kind regards

Bernd

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: 3D library

Post by MaxV » Wed May 21, 2014 2:26 pm

malte wrote:Hi, you might be way better off using the graphic primitive. Using the paint tools will be much slower.
I imagined that a single image was faster and less memory consuming; but your are saying me that is better graphic polygonal object for each 3D object?
Unfortunately if I use polygonal objects, I need one fore each face of the solid; because I need to change each face luminosity (color) to give a correct 3D effect.
Look at this picture:
Image
It's just a simple cube with only 3 faces shown, but they are 3 polygons.
I'm not an expert, but are you sure that using polygons is the best way? :D
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: 3D library

Post by MaxV » Wed May 21, 2014 2:58 pm

I write here some code to explain me better.
A the present I'm using the following code:

on mouseUp
set the style of the templateGraphic to polygon
create graphic face1
create graphic face2
create graphic face3
put "40,60" & return into temp
put "60,40" & return after temp
put "40,20" & return after temp
put "20,40" & return after temp
put "40,60" & return after temp
set the points of graphic face1 to temp
set the opaque of graphic face1 to true
set the backgroundcolor of graphic face1 to 230,0,0
put "40,60" & return into temp
put "20,40" & return after temp
put "20,80" & return after temp
put "40,100" & return after temp
put "40,60" & return after temp
set the points of graphic face2 to temp
set the opaque of graphic face2 to true
set the backgroundcolor of graphic face2 to 255,0,0
put "40,60" & return into temp
put "60,40" & return after temp
put "60,80" & return after temp
put "40,100" & return after temp
put "40,60" & return after temp
set the points of graphic face3 to temp
set the opaque of graphic face3 to true
set the backgroundcolor of graphic face3 to 200,0,0
end mouseUp

but I'd prefer images, something like :

Code: Select all

set the rect of the templateImage to 100,100,400,400
create image
choose polygon tool
#here I don't know how to continue...
What do you think?
What is the best solution?
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3255
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: 3D library

Post by bn » Wed May 21, 2014 5:48 pm

Hi Max,

I think you should go with graphics.

If you want to go with images then here is some code, combining your two scripts.

Code: Select all

set the rect of the templateImage to 10,10,400,400
   create image
   choose polygon tool
   #here I don't know how to continue...
   put "40,60" & return into temp
   put "60,40" & return after temp
   put "40,20" & return after temp
   put "20,40" & return after temp
   put "40,60" & return after temp
   
   repeat with i = 2 to the number of lines of  temp
      drag from line i - 1 of temp to line i of temp
   end repeat
   choose pointer tool
Kind regards
Bernd

ChessGredon
Posts: 24
Joined: Thu May 15, 2014 4:40 pm

Re: 3D library

Post by ChessGredon » Fri May 23, 2014 9:36 pm

MaxV, this is the REBOL language, right? Just wanted to ask, I have seen it rarely, but looks powerful, easier to write than C# and cool outfit. Is it close to LiveCode?

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: 3D library

Post by MaxV » Tue May 27, 2014 11:00 am

Yes, it is. It's very simpler and powerful. It's like Livecode, but you have to write jus few line of text, no IDE, no binary file format.

Now it's opensource and you can get the source here: https://github.com/rebol/rebol

A simple e guide to Rebol is here: http://www.re-bol.com/rebol.html
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: 3D library

Post by MaxV » Tue May 27, 2014 11:01 am

However Rebol now is abandoned, so I switched to Livecode. :D
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

FredBeck
Posts: 76
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: 3D library

Post by FredBeck » Wed May 28, 2014 1:00 pm

Hi there,
I'm very interested in this.
I'm a designer (sailing boats mainly) and amateur programmer.
I use Rhino as 3d modeler and it has a graphical programming language called grasshopper (see my page).
I'd love to see lc and gh working together.
I don't have time right now to check all these posts but
I'll be back!
F.

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: 3D library

Post by MaxV » Thu May 29, 2014 9:44 am

I'm near to finish, I have just to correct last 2 functions (render and r3d_Render2dTriangles_Simple). You can see the developments here: https://github.com/angerangel/LCR3D/blob/master/r3d.txt
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

FredBeck
Posts: 76
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: 3D library

Post by FredBeck » Thu May 29, 2014 11:25 am

Nice, I wasn't expecting so much! Thank you so much for sharing! I'll take a look soon and post my questions.
Can you put an example of
#"world" contains a list of object to render:
# it has
#[1]["model"] (contains faces and points of the boject)
#[1]["properties"] (contains traslation, rotation and other transormationof the object, very usefu in animation)
#[1]["color"] (the color to render the object)
I'll make a tool in grasshopper to format meshes correctly. I already imported polylines with a bunch of attributes the other day.

Post Reply

Return to “Extending LiveCode”