3D library
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: 3D library
May I post a couple links that could be of interest
http://www.grasshopper3d.com/forum/topi ... g-multiple
I like the idea of storing colors into one bitmap
http://www.grasshopper3d.com/group/slingshot
uses mySQL
http://www.grasshopper3d.com/forum/topi ... g-multiple
I like the idea of storing colors into one bitmap
http://www.grasshopper3d.com/group/slingshot
uses mySQL
Re: 3D library
Ok, I'll try:FredBeck wrote: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 object)
#[1]["properties"] (contains translation, rotation and other transformation of the object, very useful in animation)
#[1]["color"] (the color to render the object)
world is an array containing quite all informations of all objects present in the world to render.
For example:
- world[1] contains a red cube
- world[2] contains a blue pyramid
- world[3] contains a green apple
- world[1]["model"] contains all geometry data (vertex and faces)
- world[1]["properties"] contains all transformation data, like translations and rotations from the initial position of the vertex. It's just a 4x4 matrix.
- world[1]["color"] contain the color, like red or 255,0,0
Fore example a cube has (it isn't real code, but it show how it works):
Code: Select all
# vertices
[ 0 0 0 ] #point 1
[ 1 0 0 ] #point 2
[ 1 1 0 ] #point 3 and so on...
[ 0 1 0 ]
[ 0 0 1 ] #point 5
[ 1 0 1 ] #point 6
[ 1 1 1 ] #point 7 and so on...
[ 0 1 1 ]
#faces
# faces - anticlockwise winding
#just six face square, instead of 12 triangles
[ 4 3 2 1] # face made of points 4, 3, 2 and 1
[ 5 6 7 8 ]
[ 1 5 8 4 ] # face made of point 1, 5, 8 and 4
[ 1 2 6 5]
[ 2 3 7 6 ]
[ 8 7 3 4 ]
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: 3D library
It works :
Now I'd like to speed up drawing, at the present the code is:
Any suggestions?
Is it correct to switch continuosly between browser tool and polygon tool to draw many polygons?
Now I'd like to speed up drawing, at the present the code is:
Code: Select all
set the rect of the templateimage to 0,0,400,360
if exists(image r3d) then
delete image r3d
end if
create image"r3d"
set the brush to 1
choose the polygon tool
set the brushcolor to 170,0,0
set the pencolor to 170,0,0
drag from 174,192 to 200,210
drag from 200,210 to 200,180
drag from 200,180 to 172,163
drag from 172,163 to 174,192
choose the browser tool
choose the polygon tool
set the brushcolor to 184,0,0
set the pencolor to 184,0,0
drag from 199,149 to 172,163
drag from 172,163 to 200,180
drag from 200,180 to 227,163
drag from 227,163 to 199,149
choose the browser tool
choose the polygon tool
set the brushcolor to 163,0,0
set the pencolor to 163,0,0
drag from 227,163 to 200,180
drag from 200,180 to 200,210
drag from 200,210 to 224,192
drag from 224,192 to 227,163
choose the browser tool
Is it correct to switch continuosly between browser tool and polygon tool to draw many polygons?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: 3D library
Cool!
I'd like to keep up with you, but I'm having small health issues :(
like malte says, better go with graphic controls. Here is the thing with polyline I told you about
https://dl.dropboxusercontent.com/u/683 ... ylines.zip
it's much easier this way and probably faster.
I'd like to keep up with you, but I'm having small health issues :(
like malte says, better go with graphic controls. Here is the thing with polyline I told you about
https://dl.dropboxusercontent.com/u/683 ... ylines.zip
it's much easier this way and probably faster.
Re: 3D library
Hey I noticed you wanted off file format. Never heard of it... Does it carry color?
I think ply may be better and more spread. I'll look into it.
I think ply may be better and more spread. I'll look into it.
Re: 3D library
Here's a PLY parser, along with two test .ply files Did I get the world array right?
I didn't try your stuff yet.
https://dl.dropboxusercontent.com/u/683 ... parser.zip
EDIT : oops sorry wrong file I updated the link and code
EDIT 2 : the color thing is a mess I'm fixing it
I didn't try your stuff yet.
https://dl.dropboxusercontent.com/u/683 ... parser.zip
Code: Select all
function parsePLY pFile
set the itemDelimiter to space
## separate header from model data
put lineOffset("end_header", pFile) into tEndHeaderLine
put line 1 to tEndHeaderLine of pFile into tHeader
put line tEndHeaderLine + 1 to -1 of pFile into tData
## get number of vertices and faces
put lineOffset("element vertex", tHeader) into tVertexNumLine
put item -1 of line tVertexNumLine of pFile into tVertexNumber
put lineOffset("element face", tHeader) into tFaceNumberLine
put item -1 of line tFaceNumberLine of pFile into tFaceNumber
## separate vertex anf faces data
put line 1 to tVertexNumber of tData into tRawVertices
put line (tVertexNumber + 1) to (tVertexNumber + tFaceNumber) of tData into tRawFaces
## register points and vertex colors
repeat with p = 1 to tVertexNumber
put line p of tRawVertices into tRawVertex
repeat with q = 1 to 3
put word q of tRawVertex into tVertexArr [p] [q]
end repeat
put word 4 of tRawVertex into tVertexColorArr [p]
end repeat
## register faces
repeat with p = 1 to tFaceNumber
put line p of tRawFaces into tRawFace
put word 1 of tRawFace into tVcount
repeat with q = 2 to tVcount + 1
put word q of tRawFace into tIndex
put tIndex into tFaceArr [p] [q]
## register face color
put tVertexColorArr [tIndex] into tNewColor
put tColorArr [p] into tColor
get AverageColor(tNewColor, tColor)
put tColor into tColorArr [p]
end repeat
end repeat
put tVertexArr into tWorld ["model"] ["points"]
put tFaceArr into tWorld ["model"] ["faces"]
put tColorArr into tWorld ["color"]
return tWorld
end parsePLY
function AverageColor pNewColor @pColor
set the itemDelimiter to comma
if pColor is not empty then
repeat with x = 1 to 3
put ((item x of pNewColor + item x of pColor) / 2) into item x of pColor
end repeat
else
put pNewColor into pColor
end if
return pColor
end AverageColor
function displayArrayData pArray, pIndent
# create the variable that loops through the keys in the array
local tKey
if pArray is an array then
# print information to indicate that we are entering a new nested level of the array
get "Array" & return
# print full stops that allow the reader to track the depth of an element
put "." after pIndent
# create the indentation
put tab after pIndent
repeat for each key tKey in pArray
# call displayArrayData with a nested array
put format("%s[%s] => %s\n", pIndent, tKey, displayArrayData (pArray[tKey], pIndent)) after it
end repeat
delete the last char of it
return it
else
return pArray
end if
end displayArrayData
EDIT 2 : the color thing is a mess I'm fixing it
Re: 3D library
FIXED - colors are good now!
Code: Select all
function parsePLY pFile
set the itemDelimiter to space
## separate header from model data
put lineOffset("end_header", pFile) into tEndHeaderLine
put line 1 to tEndHeaderLine of pFile into tHeader
put line tEndHeaderLine + 1 to -1 of pFile into tData
## get number of vertices and faces
put lineOffset("element vertex", tHeader) into tVertexNumLine
put item -1 of line tVertexNumLine of pFile into tVertexNumber
put lineOffset("element face", tHeader) into tFaceNumberLine
put item -1 of line tFaceNumberLine of pFile into tFaceNumber
## separate vertex anf face data
put line 1 to tVertexNumber of tData into tRawVertices
put line (tVertexNumber + 1) to (tVertexNumber + tFaceNumber) of tData into tRawFaces
## register points and vertex colors
repeat with p = 1 to tVertexNumber
put line p of tRawVertices into tRawVertex
repeat with q = 1 to 3
put word q of tRawVertex into tVertexArr [p] [q]
end repeat
repeat with r = 1 to 3
put word (r + 3) of tRawVertex into tVertexColorArr [p] [r]
end repeat
end repeat
## register faces
repeat with p = 1 to tFaceNumber
put line p of tRawFaces into tRawFace
put word 1 of tRawFace into tVcount
repeat with q = 2 to tVcount + 1
put word q of tRawFace into tIndex
put tIndex into tFaceArr [p] [q - 1]
end repeat
end repeat
## register face colors
repeat for each key tFaceKey in tFaceArr
put tFaceArr [tFaceKey] into tArr
repeat for each key tVertexKey in tArr
put tArr [tVertexKey] into tIndex
put tVertexColorArr [tIndex] into tNewColor
get AverageColor(tNewColor, tColor)
end repeat
combine tColor using comma
put tColor into tColorArr [tFaceKey]
end repeat
put tVertexArr into tWorld ["model"] ["points"]
put tFaceArr into tWorld ["model"] ["faces"]
put tColorArr into tWorld ["color"]
return tWorld
end parsePLY
function AverageColor pNewColor @pColor
## blends the nth vertex color with the face color
repeat with x = 1 to 3
if pColor [x] is not empty then
put round((pNewColor [x] + x * pColor [x]) / (x + 1)) into pColor [x]
else
put pNewColor [x] into pColor [x]
end if
end repeat
return pColor
end AverageColor
## from Livecode Lessons
function displayArrayData pArray, pIndent
# create the variable that loops through the keys in the array
local tKey
if pArray is an array then
# print information to indicate that we are entering a new nested level of the array
get "Array" & return
# print full stops that allow the reader to track the depth of an element
put "." after pIndent
# create the indentation
put tab after pIndent
repeat for each key tKey in pArray
# call displayArrayData with a nested array
put format("%s[%s] => %s\n", pIndent, tKey, displayArrayData (pArray[tKey], pIndent)) after it
end repeat
delete the last char of it
return it
else
return pArray
end if
end displayArrayData
-
- Posts: 24
- Joined: Thu May 15, 2014 4:40 pm
Re: 3D library
That is really fantastic topic guys thanks for posting your work.
Re: 3D library
Hi max,
Here's the last version of the ply parser. Now it will handle different format of ply, provided it is ascii encoded.
all information but points, faces and color will be ignored. if color is absent, then it it set to white.
I couldn't make your code work. all I have is a list of "-31.813371;400,300:399,303:399,303:399,303" in the "tutto" field... Maybe I didn't set up the world array in the right way.
Could you make any progress regarding the graphics way?
Looking forward to hear from you.
F.
Here's the last version of the ply parser. Now it will handle different format of ply, provided it is ascii encoded.
all information but points, faces and color will be ignored. if color is absent, then it it set to white.
I couldn't make your code work. all I have is a list of "-31.813371;400,300:399,303:399,303:399,303" in the "tutto" field... Maybe I didn't set up the world array in the right way.
Could you make any progress regarding the graphics way?
Looking forward to hear from you.
F.
Re: 3D library
If you look at https://github.com/angerangel/LCR3D/blob/master/r3d.txt now there is the r3d_load_OFF function, it loads and convert file and add the scale factor to the model, this way is centered on the screen.FredBeck wrote:Hi max,
Here's the last version of the ply parser. Now it will handle different format of ply, provided it is ascii encoded.
all information but points, faces and color will be ignored. if color is absent, then it it set to white.
I couldn't make your code work. all I have is a list of "-31.813371;400,300:399,303:399,303:399,303" in the "tutto" field... Maybe I didn't set up the world array in the right way.
Could you make any progress regarding the graphics way?
Looking forward to hear from you.
F.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: 3D library
Hi all,
this video shows how the library build slowly a 3D solid: https://www.youtube.com/watch?v=Iry7hOWVLCs
I'll post a complete easy to use stack soon this month, at the present I have a lot of work for the next 2 weeks. Keep your eyes open on https://github.com/angerangel/LCR3D
this video shows how the library build slowly a 3D solid: https://www.youtube.com/watch?v=Iry7hOWVLCs
I'll post a complete easy to use stack soon this month, at the present I have a lot of work for the next 2 weeks. Keep your eyes open on https://github.com/angerangel/LCR3D
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: 3D library
Fantastic stuff MaxV!
Simon
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: 3D library
Awesome! Now I'll be able to fix my ply stuff and test a couple ideas I have regarding the drawing process. I don't really understand the forking and pulling on github but this is going to be fun! Thanks again for sharing :wink:
Re: 3D library
Status update: the first step is done, all OFF models are correctly imported and rendered.
You can use https://github.com/angerangel/LCR3D/raw ... D.livecode stack ready to use to load and render OFF models.
There are 2 buttons in the stack to load OFF model: one renders drawing it, the other one render using vector graphic.
If you create the standalone version of the stack, it's quicker and vector graphic version has no holes (that in Livecode IDE are generated by IDE to permit editing by mouse).
OFF models are in the current folder: https://github.com/angerangel/LCR3D/tre ... /3D-models
All the library is written also in plain text on https://github.com/angerangel/LCR3D/blob/master/r3d.txt , please use this file to propose patch and changes. This way control version of the library is very easy.
You are welcome to test it on your machine, to suggest any idea to improve it. I'd like to speed up rendering process. It's a livecode native library, so it should work on any device and on any operating system.
You are also welcome to fork the project and play with it on https://github.com/angerangel/LCR3D
Next step is a stack where you can play with objects and camera using scrollers: rotation, translation, deformations and so on...
This is a screenshot of the teapot test:
You can use https://github.com/angerangel/LCR3D/raw ... D.livecode stack ready to use to load and render OFF models.
There are 2 buttons in the stack to load OFF model: one renders drawing it, the other one render using vector graphic.
If you create the standalone version of the stack, it's quicker and vector graphic version has no holes (that in Livecode IDE are generated by IDE to permit editing by mouse).
OFF models are in the current folder: https://github.com/angerangel/LCR3D/tre ... /3D-models
All the library is written also in plain text on https://github.com/angerangel/LCR3D/blob/master/r3d.txt , please use this file to propose patch and changes. This way control version of the library is very easy.
You are welcome to test it on your machine, to suggest any idea to improve it. I'd like to speed up rendering process. It's a livecode native library, so it should work on any device and on any operating system.
You are also welcome to fork the project and play with it on https://github.com/angerangel/LCR3D
Next step is a stack where you can play with objects and camera using scrollers: rotation, translation, deformations and so on...
This is a screenshot of the teapot test:
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: 3D library
Update: added guide about library usage here: https://github.com/angerangel/LCR3D/wiki
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w