Per polygon material selection via script...done in mesh?

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.

Per polygon material selection via script...done in mesh? // Scriptorium

1  |  

Post by ProfessorKhaos // Jan 4, 2007, 9:36am

ProfessorKhaos
Total Posts: 622
pic
Hi all,


Past scripting experience leads me to believe that pointers to the material to be used are defined in the mesh itself on a per polygon basis. I've looked at the cone object and the terrain mesh object and neither uses more than a single material, thus no definitions are called out that I can tell.


Does anyone know if/how this can be done in the mesh itself?


I think I may be able to turn on/off segments in my LED display by pointing the appropriate polygons to the correct material instead of maintaining a separate material for each segment in the display.


Can anyone give me a coding example of material assignments in the mesh?


P.K.

Post by ProfessorKhaos // Jan 4, 2007, 10:19am

ProfessorKhaos
Total Posts: 622
pic
Got a reply in the interactive forum and a direction to look but I'm still having a bit of difficulty trying to comprehend how to get at the data code-wise. I'll keep plugging away for a little bit. Maybe I can get it on my own but an actual example might be helpful.


Thanks!


P.K.

Post by tomasb // Jan 4, 2007, 11:19am

tomasb
Total Posts: 261
Got a reply in the interactive forum and a direction to look but I'm still having a bit of difficulty trying to comprehend how to get at the data code-wise. I'll keep plugging away for a little bit. Maybe I can get it on my own but an actual example might be helpful.


Thanks!


P.K.


example attaches material index stream and sets material for first triangle to index 1 and 0 to other.

You can get names other stream by inspecting registred data objects when adding connectors...



function OnComputeOutputs(params)

{

Mesh = params.conValue('inMesh');


// create output mesh from input

dwTris = Mesh.GetNumTriangles();

if (!dwTris)

return;


spMaterialStream = System.CreateDO('Space 3D Package/Material Index Stream Data');


spMaterialStream.SetNumMaterialIndices(dwTris);


//initialize to 0

for (i = 0; i<dwTris;i++) {

spMaterialStream.index(i) = 0;

};


//set material for 1st triangle to 1

spMaterialStream.index(0) = 1;



//attach material stream to mesh

Mesh.AttachTrianglesStream(spMaterialStream);


// put output value

params.conValue("Mesh") = Mesh;

}

Post by ProfessorKhaos // Jan 4, 2007, 11:23am

ProfessorKhaos
Total Posts: 622
pic
A perfect example!!! Thank you! I can do something with this!

Post by tomasb // Jan 4, 2007, 11:34am

tomasb
Total Posts: 261
one more addition. if the stream is present in the mesh, you can use




spMaterialStream = Mesh.GetTrianglesStreamByName('Material Index Stream Data');




directly, so you can perform modifications and not rebuilding. unfortunately in 7.11 there is no way to detect if the stream is present or not; you will get script error when stream not present...
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