Game Development Community

Accessing child objects and changing their material properties ?

by Juggernaut · in Torque 3D Professional · 01/29/2013 (2:12 am) · 11 replies

Hello,

Suppose I have imported a skinned ( rigged ) 3D model within my level which is composed of 20-25 smaller 3D objects (meshes). I want to get access to each of those 20-25 smaller 3D objects ( child objects ) through script and change their material properties by applying custom textures and custom shaders at run-time to them. Is this possible in torque3D ? How do I do this ? Any tutorial on this ?

Can I apply custom shaders and lights to torque particles through script ?

Am I limited to 8 lights in my scene ? If not then how many lights can I display simultaneously in my scene all visible at the same time within the frustum ?

Thanks,

#1
01/29/2013 (6:36 am)
I think that you have to know what the individual mesh is called by name to access it. Have a look through the Script Manual CHM file for the functions you need. I think setSkin() function might be the one T3D uses at runtime/creation of object. There's probably some stock script for this in Full Project as each time a player model spawns it chooses a new colour/material for it's suit.

I don't think that particles are currently using shaders or materials, though someone was considering developing that - but I can't remember the details.

In normal lighting (advanced) you can have as many lights as you like, but rendering each adds stress to performance, especially if you have many overlapping lights. And this increases with them casting shadows.

Lowest Lighting Quality setting (aka "Basic Lighting") limits the number of lights that reflect on an object in realtime to 4 - which is why all lights have a priority setting for sorting which ones get to go first.
#2
01/29/2013 (10:20 am)
Thank you very much for your post Sir. I am very new Torque3D. I stumbled upon Torque3D 2.0 as shown here https://www.garagegames.com/community/blogs/view/22074

I have downloaded the Complete Torque 3D 2.0 zip package available in this link - http://mit.garagegames.com/Torque3D-2.0.zip mainly because I was lost after I downloaded the one available at GIT HUB.

The Torque3D-2.0.zip contains pre-compiled of Project Manager and each of the templates. Now for the updated FPS tutorial that is at per with version 2.0, I downloaded the Torque3D-FPSTutorial found here https://github.com/GarageGames

But after expanding the zip I did not find any tutorial apart from the source code file. My question - is the online FPS tutorial compatible with version 2.0 ?

Secondly what is the name of the basic unit that represents a 3D model within the Torque3D engine world ? Is it - player or object ? Can you please clarify ?
#3
01/29/2013 (2:34 pm)
The FPS Tutorial on github is seperate, try here: github.com/GarageGames.

You can also find all of the documentation there too. If the "Torque Script Manual.chm" is blank when you open it, you need to right click on the icon and choose "unblock", for some reason Windows stops access for security but does not tell you it's done this!

"player or object ?" - player is a "player model" (as in the object under direct control of the human. Other models are just objects. The basic non-moving object (like a building) is a TsStatic type. Read the documentation from the link above (or under support-documentation-torque3d on the website) www.garagegames.com/documentation/torque-3d - it'll help explain things.
#4
01/29/2013 (2:39 pm)
Are you mounting objects or trying to update individual materials? I am not sure how to do the latter. But changing a material on 1 object is relatively easy.
#5
01/29/2013 (3:27 pm)
@Frank Carney: I am trying to learn how much low level access do I have at run-time through torque script like - loading a new object, spawning a new player model, bone manipulation of a skinned object, alteration of material ( assigning new shaders or passing parameters to shaders ) of a skinned player object or a static object etc.

I want to do at run-time using torque-script and not using the world editor. World editor is good for design but I need to have control on everything through script also at run-time.

Though script reference is available, advanced tutorials on the above mentioned topics is not covered in depth.

So if there are tutorials on those kindly point me to the right url.

@Steve Acaster: In the FPS tutorial that I downloaded from GIT, I did not find any tutorials except a bunch of source code files and folders. I do not know how to take advantage of those things. Thank you for the technical explanation and URL .... I think I will find my required info in that URL. I will post again if I am stuck.
#6
01/29/2013 (5:22 pm)
Ah, got you. My misreading.

On this website click "products->Torque3D" from the drop down menu above and then the button marked "beginner tutorial" and then "get started".
#7
01/29/2013 (9:11 pm)
"Suppose I have imported a skinned ( rigged ) 3D model within my level which is composed of 20-25 smaller 3D objects (meshes). I want to get access to each of those 20-25 smaller 3D objects ( child objects ) through script and change their material properties by applying custom textures and custom shaders at run-time to them."

very much possible.1st u have to make seperate material for each mesh from a modeling soft.then just look into soldier model's set skin method

#8
01/29/2013 (11:00 pm)
Yes this is possible.

You can hide and show individual meshes in a shape with this command

%client.player.setMeshHidden("MeshName1", false);
%client.player.setMeshHidden("MeshName2", true);

And change the material using this command

%client.player.changeMaterial("MeshName1_Mat1", 0, "MeshName1_Mat2");

Obviously the meshes have to exist and the name be known, and the material needs to be in the shapes material.cs file

Here is a small video of this sort of thing in action



In this the creation phase is a server created for the purpose on the client machine. Once in game the client is remotely connected to a dedicated server. I mention this because I can get the mesh hiding working in both situations, but I cannot get material swapping in the client -> dedicated server scenario.....

Also, you need a source code fix applied to get changeMaterial working. The fix is somewhere on the GG site but I do not have the link handy, I will post later if needed.

Cheers,

Andy



#9
01/30/2013 (1:17 am)
@Steve Acaster: I will begin with the beginner's tutorial on the website as you have shown.

@Ahsan: Thank you for the tip. I will look into the soldier model's set skin method.

@Andy Hubbard: Your video is just excellent! So I do not have to parse through the entire hierarchy of objects in the skinned model .... Torque3D will handle that automatically for me ?
#10
01/30/2013 (6:42 am)
Quote:
And change the material using this command

%client.player.changeMaterial("MeshName1_Mat1", 0, "MeshName1_Mat2");

Obviously the meshes have to exist and the name be known, and the material needs to be in the shapes material.cs file
So, no - you don't have to parse through them. You do need to know their names and have all of your materials properly defined.
#11
01/30/2013 (8:03 am)
@Richard Ranft: Thank you for the confirmation. :)