|
Script Reference guide for Procedural Modeling.
About Truespace Archives
These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.
They are retained here for archive purposes only.
Script Reference guide for Procedural Modeling. // Archive: Tech Forum
Post by Délé // Feb 15, 2006, 10:06am
Délé
Total Posts: 1374
|
Thanks Peter. :) I'm looking in on this stuff you're posting too. Nice of you to swing by and help out.
Well, I came across what I thought might be a helpful website to some of those others looking into diving in deep. :) I just perused through it but it looks like it has some good info on some 3d mathematics.
http://chortle.ccsu.edu/VectorLessons/vectorIndex.html |
Post by Johny // Feb 16, 2006, 8:24pm
Johny
Total Posts: 672
|
Peter, thanks for complete renderable script plane. :)
I also have another question:"So far we just make a triangle faces. is it posible to script out a non triagle face?"
Hey De'le', thanks for the usefull link :) |
Post by tomasb // Feb 16, 2006, 10:58pm
tomasb
Total Posts: 261
|
"So far we just make a triangle faces. is it posible to script out a non triagle face?"
Yes. Triangle stream group contains triange edge stream that says for each triangle which edge is boundary. If this stream is not present, all edges become boundary by default (triangles).
For example, when you want to create quad with triangle vertex indices 0,1,2 and 0,2,3; triangle edges stream will contain this (in binnary):
011 [edge 2-0 is not set, edges 1-2 and 0-1 are set]
110 [edges 2-3 and 3-0 are set, edge 0-2 is not set]
Beware, that neighboring triangles should have common edge both set or not. Otherwise it may confuse PE selection tools or SDS.
hth. |
Post by Johny // Feb 17, 2006, 7:42pm
Johny
Total Posts: 672
|
Tomas Bujnak, thanks for the answer and explaination about Triangle Edge Stream.
I already search it from sample script object that come with ts7, but I didn't found any sample script object used this triangle edge stream. So I didn't know how to use it on script object.
Can You post some codes that change above script plane object become not triangle object? |
Post by Leif // Feb 17, 2006, 7:48pm
Leif
Total Posts: 276
|
Wow have you checked the view number for this thread ? Must be popular topic! |
Post by Johny // Feb 20, 2006, 7:07am
Johny
Total Posts: 672
|
I tried with this code :
dE=System.CreateDO("Space 3D Package/Face Edges Stream Data");
dE.SetNumTriangleEdges(2);
dE.edges(0,2);
...
But I got error on code dE.edges(0,2);
Can anybody help me to solve this problem:confused:
(I need non triagle face for use with sweep tool.:rolleyes: |
Post by scapino // Feb 20, 2006, 8:08pm
scapino
Total Posts: 101
|
dE=System.CreateDO("Space 3D Package/Face Edges Stream Data");
dE.SetNumTriangleEdges(2);
dE.edges(0.2);
...
Looks like theres a . (period), instead of a comma in dE.edges(0.2);
Kurt |
Post by peterma // Feb 22, 2006, 1:14am
peterma
Total Posts: 48
|
I tried with this code :
dE=System.CreateDO("Space 3D Package/Face Edges Stream Data");
dE.SetNumTriangleEdges(2);
dE.edges(0,2);
...
But I got error on code dE.edges(0,2);
I tested that and yes - edges is a property so you should use this format to set the value
dE.edges(0) = 2
or this one to read the value
myVal = dE.edges(0)
I do agree this is not easy to deduct from our code competion methods list, where methods and properties are not distingished. I'll try to improve this.
For now a little hepler - when you see 2 same methods in the code completion list and they differ in number of parameters, most likely it represents get and set property forms and you should use it like property. |
Post by Johny // Feb 24, 2006, 5:30am
Johny
Total Posts: 672
|
Peter, thanks for the explanation about how to use/read code auto complete options. ;)
But I still failed to script out a non triangle object :(
is "Face Edges Stream Data" can be use to make something like Tomas wrote in this post click here (http://forums1.caligari.com/truespace/showpost.php?p=2296&postcount=33)? |
Post by peterma // Feb 24, 2006, 8:11am
peterma
Total Posts: 48
|
this is a working example. Check it in wireframe mode. |
Post by Asem // Feb 24, 2006, 9:01am
Asem
Total Posts: 255
|
From Script:
// edges
dE=System.CreateDO("Space 3D Package/Face Edges Stream Data");
dE.SetNumTriangleEdges(2);
dE.edges(0) = 3 // 011 binary
dE.edges(1) = 6 // 110 binary
I understand where the numbers are coming from but can you explain more on how it is connecting the edges. Is 011 related to the vertice stream or the triangle stream?How does it relate to them? :confused:
I did a plane of my own with triangles and have figured how to use the vertices and triangles steams but now this is confusing. |
Post by tomasb // Feb 24, 2006, 9:18am
tomasb
Total Posts: 261
|
I understand where the numbers are coming from but can you explain more on how it is connecting the edges. Is 011 related to the vertice stream or the triangle stream?How does it relate to them? :confused:
I did a plane of my own with triangles and have figured how to use the vertices and triangles steams but now this is confusing.
Edge stream specifies, which edges are "on" and which are "off" for each triangle. You need to make sure, that edge and it's corresponding pair are both On or Off.
N-th bit set means, that there is edge P[N],P[(N+1) mod 3] (where P are triangle indices) in the mesh. |
Post by Asem // Feb 24, 2006, 10:57am
Asem
Total Posts: 255
|
Edge stream specifies, which edges are "on" and which are "off" for each triangle. You need to make sure, that edge and it's corresponding pair are both On or Off.
N-th bit set means, that there is edge P[N],P[(N+1) mod 3] (where P are triangle indices) in the mesh.
Okay, so should I see it as:
dE.edges(P) = N mod 3;
Where if you look at N as 3 binary bits:
P is 0
1st_bit 0 = P i
2nd_bit 1 = P j
3rd_bit 1 = P k
Where then 011 is 3 because from right to lift 2^0 + 2^1 + 0.
Correct me if I'm wrong and if that is the case why have dE.edges(0) when in the script dE.edges seems to be the one to actually remove the edge that makes it a triangle? Unless you have to at least specify two. |
Post by tomasb // Feb 24, 2006, 11:21am
tomasb
Total Posts: 261
|
One image that may make it clear.
It shows 1 polygon that consists of 4 triangles.
Polygon has vertices with indices 0,1,2,5,4,3.
internal edges are 1,3; 3,1; 1,4; 4,1; 2,4; 4,2. (not boundary)
boundary edges are 0,1; 1,2; 2,5; 5,4; 4,3; 3,0
Internal edges DON'T have the flag set, boundary have.
triangles stream (index: i,j,k):
0: 0,1,3
1: 1,4,3
2: 1,2,4
3: 2,5,4
corresponding face edges stream (triangles: bits for edge ki,jk,ij):
0: 101 (edge 0,1 set; edge 3,0 set)
1: 010 (edge 4,3 set)
2: 001 (edge 1,2 set)
3: 011 (edge 2,5 set; edge 5,4 set).
if you want to know if triangle T contains edge between vertices triangles[T].P[i] and triangles[T].P[(i+1) % 3] that is on polygon boundary, then take face edges stream and check, if bit P is set. (dE.edges(T) & (1 << p)). If it is not set, that means that edge is inside polygon.
{note that P[0] = i, P[1] = j, P[2] = k} |
Post by Asem // Feb 24, 2006, 11:53am
Asem
Total Posts: 255
|
Thanks that completly explained it :D It was actually confusing because I didn't know that the bits were grouped this way " corresponding face edges stream (triangles: bits for edge ki,jk,ij)."
Someone should start something at wikipedia,there's a lot of info here :D |
Post by Johny // Feb 25, 2006, 3:12am
Johny
Total Posts: 672
|
Peter, thanks again for your help.
Here is screen grap of obj panel and RsObj file of my script plane object. |
Post by peterma // Feb 26, 2006, 10:13am
peterma
Total Posts: 48
|
Very nice, we have perfect plane now :) |
Post by SiRender // Feb 26, 2006, 1:40pm
SiRender
Total Posts: 38
|
Peter, thanks again for your help.
Here is screen grap of obj panel and RsObj file of my script plane object.
When I use "Double Size Plane" it looks strange. Does anyone know what's going on? |
Post by Cayenne // Feb 26, 2006, 2:33pm
Cayenne
Total Posts: 144
|
I think it is showing like this as there is currently no uv co-ordinates for the object, if you apply planar uv to the plane then the "strangeness" goes away |
Post by Johny // Feb 26, 2006, 5:33pm
Johny
Total Posts: 672
|
SiRender, temporay you can fix it by apply a material to plane object.:rolleyes:
Peter, I tried to add UV coordinat to the script plane but I don't know how to attatch it to plane mesh :confused:
// try to fix UV problem at double size script plane object
function OnComputeOutputs(params)
{
inSize = params.ConValue('inSize');
// vertices
dV = System.CreateDO("Space 3D Package/Vertex Stream Data");
dV.SetNumVertices(4);
dV.x(0)=0;
dV.y(0)=0;
dV.z(0)=1;
dV.x(1)=inSize;
dV.y(1)=0;
dV.z(1)=1;
dV.x(2)=inSize
dV.y(2)=inSize
dV.z(2)=1;
dV.x(3)=0;
dV.y(3)=inSize
dV.z(3)=1;
dUV = System.CreateDO("Space 3D Package/UV Coordinate Stream Data");
dUV.SetNumUVCoords(4);
dUV.u(0)=0;
dUV.v(0)=0;
dUV.u(1)=1;
dUV.v(1)=0;
dUV.u(2)=1;
dUV.v(2)=1;
dUV.u(3)=0;
dUV.v(3)=1;
dTUV = System.CreateDO("Space 3D Package/UV Triangle Stream Data");
dTUV.SetNumUVTripleIndices(4);
dTUV.i(0)=0;
dTUV.j(0)=2;
dTUV.k(0)=3;
dTUV.i(1)=0;
dTUV.j(1)=2;
dTUV.k(1)=3;
dTUV.i(2)=0;
dTUV.j(2)=1;
dTUV.k(2)=2;
dTUV.i(3)=0;
dTUV.j(3)=2;
dTUV.k(3)=3;
// triangles
dF = System.CreateDO("Space 3D Package/Triangle Vertices Stream Data");
dF.SetNumTripleIndices(4);
dF.i(0)=0;
dF.j(0)=1;
dF.k(0)=2;
dF.i(1)=0;
dF.j(1)=2;
dF.k(1)=3;
dF.i(2)=1;
dF.j(2)=3;
dF.k(2)=2;
dF.i(3)=1;
dF.j(3)=0;
dF.k(3)=3;
// edges
dE=System.CreateDO("Space 3D Package/Face Edges Stream Data");
dE.SetNumTriangleEdges(4);
dE.edges(0) = 3 // 011 binary
dE.edges(1) = 6 // 110 binary
dE.edges(2) = 6 // 011 binary
dE.edges(3) = 3 // 110 binary
dM=System.CreateDO("Space 3D Package/Mesh Data");
dM.AttachVerticesStream(dV);
dM.AttachTrianglesStream(dF);
dM.AttachTrianglesStream(dE);
// dM.AttachFacesStream(dTUV);
params.ConValue('outMesh') = dM;
} |
Post by SiRender // Feb 26, 2006, 11:28pm
SiRender
Total Posts: 38
|
Ah. Yea, it was the UV.
Johny, I didn't try your code yet. But, I noticed that when I apply the UV planar map, the internal connection between "Plane Mesh" and "Shape" gets removed in the object -- so your code solution will be nice. :)
EDIT: actually the connection gets removed I think if you go into point edit mode in the model view |
Post by peterma // Feb 27, 2006, 12:41am
peterma
Total Posts: 48
|
Peter, I tried to add UV coordinat to the script plane but I don't know how to attatch it to plane mesh :confused:
Johny, UV stream is a custom stream in Rosetta mesh model, and so far we don't have good access methods for manipulating such a stream from scripts. Tomas is working on it and it should be fixed in tS7.02 patch. |
Post by Johny // Feb 27, 2006, 1:49am
Johny
Total Posts: 672
|
Thanks for let me know about that. ;)
Now I must wait until the next patch.:cool:
Talk about next patch, I have request for primitive plane object with X and Y resolution parameters. And primitive cube object with X,Y and Z resulution parameters.
like on this image:D |
Post by tomasb // Feb 27, 2006, 2:12am
tomasb
Total Posts: 261
|
Thanks for let me know about that. ;)
Now I must wait until the next patch.:cool:
Adding custom streams is possible, but not reading them because there are problems with sending GUID*.. you CAN make the plane object with UV coordinates with current version.
Use AttachCustStream in your plane script to add UV data and AddTrianglesStream to add UV indices to UV data..
.
.
dM.AttachTrianglesStream(dTUV);
dM.AttachCustStream(dUV);
.
. |
Post by Johny // Feb 27, 2006, 5:28am
Johny
Total Posts: 672
|
TomasB, I already followed your suggestion but that's nothing changed as you can see at bellow image. :confused:
With this post, I also attach the tested RsObj file. So You can also check it by yourself.:rolleyes: |
Post by marekk // Feb 28, 2006, 11:17pm
marekk
Total Posts: 10
|
This is observable in Player only as far as I know. Calculation of UV on planar object (which is in fact 2D) is numerically unstable. The problem is not located yet, but it can be avoided by using very thin box instead plane, with planar or cubic UV mapping. |
Post by SiRender // Mar 1, 2006, 10:57pm
SiRender
Total Posts: 38
|
Ah. So it's like when I move two objects so a couple coplanar faces align. The round error from the underlying algorithms bubbling up as it tries to figure out who's point is visible from each face, right? :)
Why does applying a planar UV fix it though as the others suggested?
Thanks! |
Post by Johny // Apr 4, 2006, 1:00am
Johny
Total Posts: 672
|
Anyone know how to use IRdInputState's "GeyKeyState" for capture input from keyboard? |
Post by tomasb // Apr 4, 2006, 1:26am
tomasb
Total Posts: 261
|
Anyone know how to use IRdInputState's "GeyKeyState" for capture input from keyboard?
A bit unintended usage for that DO, but... create IRdInputState data object.
Param for GetKeyState is virtual key code. It just calls GetAsyncKeyState, so you can check MSDN for virtual key codes. return is bool which is true if key is pressed, false otherwise. |
Post by Johny // Apr 4, 2006, 3:51am
Johny
Total Posts: 672
|
Tomasb, thanks for the information, I will check it :) |
|