Reputation: 57
is there any way to extract the "Dress fbx" from "femal 2 fbx" ? because I want to change the clothes of the avatar in run time so I want to extract the "Dress fbx" and save it in database then in run-time if I click on specific button I want the avatar dress this "Dress fbx". Is this method correct?
EDIT
when I clicked on the button and run this code I get this error
public class DressController:MonoBehaviour
{
[SerializeField] private GameObject dressObj = null;
public void SetDressWithColor(Color color){
this.dressObj.GetComponent<MeshRenderer>().material.color = color;
}
}
EDIT 2
I deleted the dress mesh from the female fbx using 3dmax, then I imported the female fbx into unity, and tried to add dress mesh to female in run time when I click on button, but the dress didn't put on the female why?, this code that I am using when I click on button
//I set this public variables in the Unity editor
public Mesh mesh = null; //Dress mesh
public Material material = null; //Dress_Diffuse
public Transform t = null; // CC_Base_BoneRoot
public void SetDressWithMesh()
{
var smr = this.dressObj.GetComponent<SkinnedMeshRenderer>();
smr.rootBone = t;
smr.sharedMesh = mesh;
smr.material = material;
}
t is the Root Bone for dress (in my code is "CC_Base_BoneRoot") as showing in the picture
Upvotes: 1
Views: 1118
Reputation: 10721
You are most likely not using a fbx at runtime. When you drag the fbx in Unity, it gets converted to a hierarchy of gameobject that contains MeshRenderer and MeshFilter pointing to the meshes and materials. This is what you show in the pic.
When you drag this in a scene, it turns into a game object and this is what you will be dealing with.
In your case you want to affect the dress child object. So first you'd find that one or drag it. Then it depends whether you want to change the dress mesh or just its material. In the first case, you can affect the shape, in the second case, you can affect the colors and texturing.
public class DressController:MonoBehaviour
{
[SerializeField] private GameObject dressObj = null;
public void SetDressWithColor(Color color){
this.dressObj.GetComponent<SkinnedMeshRenderer>().material.color = color;
}
public void SetDressWithMesh(Mesh mesh, Material material){
var smr = this.dressObj.GetComponent<SkinnedMeshRenderer>()
smr.sharedMesh = mesh;
smr.material = material;
}
}
In the case of a mesh update, you'd need to change the material as well since the UV map and so on will not match anymore.Also, your MeshRenderer may use multi materials.
To sum it up, you would address the MeshRenderer, Material and MeshFilter for your case.
Upvotes: 1