x


Can I modify a mesh via editor scripts

Hi there,

I try to combine the sub mesh of a fbx model to root when importing it. I've combined sub mesh successfuly at runtime before. But when I do the same via editor script ( in OnPostprocessModel() in a subclass inherits from AssetPostprocessor), the result mesh is null. The part of code like this:

    SkinnedMeshRenderer render = go.GetComponent<SkinnedMeshRenderer>() as SkinnedMeshRenderer;
    if (render == null)
        render = go.AddComponent<SkinnedMeshRenderer>() as SkinnedMeshRenderer;

    render.sharedMesh = new Mesh();
    Debug.Log("combine count is " + combines.Count.ToString());
    render.sharedMesh.CombineMeshes((CombineInstance[])combines.ToArray(typeof(CombineInstance)), false, false);
    Debug.Log("render.sharedMesh.subMeshCount is" + render.sharedMesh.subMeshCount.ToString());
    Debug.Log("render.sharedMesh.vertexCount is" + render.sharedMesh.vertexCount.ToString());
    render.sharedMaterials = (Material[])materials.ToArray(typeof(Material));
    render.bones = (Transform[])bones.ToArray(typeof(Transform));

The log shows that the subMeshCount and vertexCount of result sharedMesh are not zero. But when I dorp the asset to sence it shows nothing, and the inspector shows it's mesh is missing while all materials exist. I guess it's due to I can't save the result to the import asset because it's a fbx file, or is there something I've missing ? I'll be very greatful on your help.

more ▼

asked Apr 04 '11 at 07:25 AM

mcwind gravatar image

mcwind
83 6 6 14

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

You created an instance of Mesh in memory, but the Mesh is not saved as asset. I've never done this with a mesh, but i guess you have to use AssetDatabase.AddObjectToAsset. The example there adds an AnimationClip to a material. The clip shows up as child of the material ( kinda crazy ;) ).

more ▼

answered Apr 04 '11 at 11:21 AM

Bunny83 gravatar image

Bunny83
45.5k 11 49 207

Thank you for the suggestion, I'll do some test later and feed back.

Apr 07 '11 at 03:03 PM mcwind
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1678
x96
x31

asked: Apr 04 '11 at 07:25 AM

Seen: 1157 times

Last Updated: Apr 04 '11 at 07:25 AM