Scripting problem

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.

Scripting problem // Archive: Tech Forum

1  |  

Post by thierry_st_malo // May 25, 2006, 4:19am

thierry_st_malo
Total Posts: 10
Hi, all!

I seem to have a problem with tS7's macro recorder. What I try to do is to get a script that will move the selection up (Z axis) by a given amount.

Can anybody help ?

Thanks,

Thierry

Post by Délé // May 25, 2006, 4:55am

Délé
Total Posts: 1374
pic
Try this:


- Select which macro recorder you would like to use. Jscript or VBscript.

- Select your object

- Hit record on the macro recorder toolbar

- Move your object in the Z axis in the player by right click drag on the horizontal plane of the object widget

- Stop the macro recording

- Now you can go inside of the script object by clicking on the orange triangle on the script object in the Link Editor. When inside you can type in the specific value you want for any of the three axes. Example below uses Jscript and shows where you would change the value for Z.


hth

Post by thierry_st_malo // May 29, 2006, 8:16pm

thierry_st_malo
Total Posts: 10
Thanks, Délé!

This works perfectly, but for a whole object, and I need to move a single face or even a single vertex.

When I try to do that, either by using a widget or by clicking and dragging as we did back in the old tS6 days, I get an empty ApplyMacro subroutine. Can you help or can you tell me where I can find a document that will tell me what are the components of an object and how I can get at them?


Thanks in advance,

Thierry :)


P.S: This is a very important question for me, as it would enable me to drop another 3D modeller and use tS7 as my only modelling tool.

Post by tomasb // May 29, 2006, 11:05pm

tomasb
Total Posts: 261
Thanks, Délé!

This works perfectly, but for a whole object, and I need to move a single face or even a single vertex.

When I try to do that, either by using a widget or by clicking and dragging as we did back in the old tS6 days, I get an empty ApplyMacro subroutine. Can you help or can you tell me where I can find a document that will tell me what are the components of an object and how I can get at them?


Thanks in advance,

Thierry :)


P.S: This is a very important question for me, as it would enable me to drop another 3D modeller and use tS7 as my only modelling tool.


if you want to move just a vertex or face, object need to be in point edit mode and vertex or face needs to be selected (the idea is that you capture macro for one face, then select another face and execute macro... [the problem is that the macro cannot contain selecting]).


If you want directly mapulate meshes, you need to work with mesh streams which is a bit more complex... read value of Shape node (or mesh modifier) mesh input connector, get mesh vertex stream, modify it, and put the mesh back to shape/mesh modifier node input. (in this way you have full access to all mesh streams (uvs, normals, tangent spaces, subdiv levels, materials,...)


if you want to script point edit tool, then during point edit mode selected objects export Selection connector. this contains information about selection - like indices of selected vertices, edges, triangles or face triangles. You can create command and place it into scene and add a script to execute it to toolbar or directly to button on a command node panel.

Post by mendrak // May 30, 2006, 6:16pm

mendrak
Total Posts: 18
I am interested in doing a script that manipulates a mesh. It sounds like I want to use the mesh stream. Is there something that describes mesh stream or a sample script that I should look at? I want to set the normals in addition to adding vertices when this script manipulates the mesh.


I don't remember seeing anything describing the contents of the data objects or how to get/set their attributes.

Post by thierry_st_malo // May 30, 2006, 8:11pm

thierry_st_malo
Total Posts: 10
Yes, Tomas.

Where can I find a document or a working example that would help me?

I have looked at scripted objects such as the Cone, the waving Pillar or the Terrain generator, but it looks like they always create a new mesh. I don't want to create a new mesh, I want to move or nudge part of it.

Thanks in advance,

Thierry :confused:

Post by tomasb // May 30, 2006, 10:22pm

tomasb
Total Posts: 261
ok, so some basics:


mesh rS is composed from triangle, vertex and custom streams. Triangle stream contains properties that are associated with triangles - material, vertex indices, UV indices, normal indices... vertex stream contains data that are intended for vertices - position, vertex color, ... and custom stream contains all other data. for example UV coordinates.


You get vertex stream by calling GetVerticesStreamByName method of mesh,

triangle streams are accessible thru GetTrianglesStreamByName and custom thru GetCustomStreamByName.


To modify stream (not changing topology) read mesh connector, read streams you want (vertex coords, normals,uvs,..) and attach them back to mesh. then set changed mesh to output. If you want to alter number of vertices or triangles, you need to create new mesh data object, read streams from input mesh, alter them and attach to new mesh. You cannot attach streams to old mesh since integrity checking is performed when attaching streams and number of vertices/triangles would not match.



to understand rs mesh streams here is a simple quad with material example:

triangle in indices stream:

0,1,2

0,2,3


triangle material:

0

0


triangle UV indices

0,1,2

0,2,3


vertex coordinates stream:

0: (0,0,0)

1: (1,0,0)

2: (1,1,0)

3: (0,1,0)


uv coords custom stream:

0: (0,0,0)

1: (1,0,0)

2: (1,1,0)

3: (0,1,0)


faces are specified by marking triangle edges, normals smoothing is specified by normal indices.

Post by thierry_st_malo // May 31, 2006, 11:21pm

thierry_st_malo
Total Posts: 10
Thanks, Tomas!

One more question (the last one,hopefully :o ): I will run my script while the mesh I am working on is in point edit mode. So, how can I tell which vertex, edge or face is selected?

Sorry for the trouble I am giving,

Thierry

Post by tomasb // May 31, 2006, 11:36pm

tomasb
Total Posts: 261
Thanks, Tomas!

One more question (the last one,hopefully :o ): I will run my script while the mesh I am working on is in point edit mode. So, how can I tell which vertex, edge or face is selected?

Sorry for the trouble I am giving,

Thierry


there is one problem with this - due to optimizations each point edit node needs to implement one interface... You can implement point edit tool in script but it needs to be outside of the object - encapsulate your object, take output mesh and connect it to your tool. export matrix and material connectors. then select your object (inside encapsulator) and enter point edit.


During point editing, mesh stream contains special streams so each node can detect what is selected together with lookup index to control (pipeline input) mesh element. Vertex selections are stored in IRdVertexSelectionStream, each element contains vertex weight and lookup index. Edges are in IRdEdgeSelectionStream (stored in triangle stream group) where for each triangle edge there is a bool and lookup index (triangle*3 + edge index), triangles are in IRdTrinagleSelectionStream - bool and dword for each trinagle.

For optimizations, there is timestamp stream, which says what can change when user manipulates the mesh. this is performed by IRdTriangleTimestampStream custom stream - it contains timestamps for each block of triangles and total number of triangles that may be modified (including topology changes) (this may be -1 if this info is not supported by previous node).

Post by mendrak // Jun 2, 2006, 1:43pm

mendrak
Total Posts: 18
This sorta made sense to me, since I am starting down the path to trying to do something similiar, but I've got some gaps in my understanding.


What I want to do is create a balooning effect on a selected set of faces. So in point edit mode, I want to be able to add a "custom script icon" into the menu that appears when doing point edit. (I'm not sure that's possible, but everything seems so customizable that it seems like it should be). Failing a direct incorporation into the point edit toolbar menu, I'd just have a "command jscript" in the LE that I could fire.


So some of the gaps I have are:


* Can/how would I incorporate a "command jscript" into the point edit menu.

* How does a "command jscript" know which object is currently selected?

* Once I've done building a new mesh (with the extra vertices added) how do I incorporate it into the original node?


Is there an example script that does anything similiar to this?


thierry_st_malo, if you really are doing a script like this (and it seems you might be from your posts) I'd love to see how you solved these problems.


Thanks for any advise or ideas.

Post by tomasb // Jun 3, 2006, 5:54am

tomasb
Total Posts: 261
This sorta made sense to me, since I am starting down the path to trying to do something similiar, but I've got some gaps in my understanding.


What I want to do is create a balooning effect on a selected set of faces. So in point edit mode, I want to be able to add a "custom script icon" into the menu that appears when doing point edit. (I'm not sure that's possible, but everything seems so customizable that it seems like it should be). Failing a direct incorporation into the point edit toolbar menu, I'd just have a "command jscript" in the LE that I could fire.

So some of the gaps I have are:

* Can/how would I incorporate a "command jscript" into the point edit menu.


you can check toolbar prototypes encapsulator/pointedit. this toolbar is opened when you enter point edit. Each button has it's small script which is executed when you lclick or rclick on it. You can execute jscript commands in this way. (Activity.Run('/LE path/my activity');)



* How does a "command jscript" know which object is currently selected?


check Node.FirstSelected() script command.



* Once I've done building a new mesh (with the extra vertices added) how do I incorporate it into the original node?


In selected node find mesh modifier node and set it's input mesh connector. this will change the mesh. i recomend to read mesh from input of mesh modifer node and then writting it back. You can make tool more robust by tracking Selection connector.



Is there an example script that does anything similiar to this?


i'm not sure, but i think no.

Post by mendrak // Jun 16, 2006, 6:21am

mendrak
Total Posts: 18
During point editing, mesh stream contains special streams so each node can detect what is selected together with lookup index to control (pipeline input) mesh element. Vertex selections are stored in IRdVertexSelectionStream, each element contains vertex weight and lookup index. Edges are in IRdEdgeSelectionStream (stored in triangle stream group) where for each triangle edge there is a bool and lookup index (triangle*3 + edge index), triangles are in IRdTrinagleSelectionStream - bool and dword for each trinagle.
For optimizations, there is timestamp stream, which says what can change when user manipulates the mesh. this is performed by IRdTriangleTimestampStream custom stream - it contains timestamps for each block of triangles and total number of triangles that may be modified (including topology changes) (this may be -1 if this info is not supported by previous node).

I've been searching, but I can't figure out how to retrieve the VertexSelectionStream. Is it part of the mesh object? I see the MeshSelection data object, but I'm not sure how to retrieve that either.

I tried.

selectedName = Node.FirstSelected();
if (selectedName != null)
{
m = Node.Value(selectedName, 'MeshSelection');
}

but no luck
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn