Combine meshes without moving the mesh?

Hello!
How can i combine 2 meshes without moving them if the parent is not at position 0,0,0?

@script RequireComponent(MeshFilter)
@script RequireComponent(MeshRenderer)
function Start () {
var meshFilters = GetComponentsInChildren(MeshFilter);
var combine : CombineInstance[] = new CombineInstance[meshFilters.length];
for ( i = 0; i < meshFilters.length; i++){
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
}
transform.GetComponent(MeshFilter).mesh = new Mesh();
transform.GetComponent(MeshFilter).mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}

I don’t see why the meshes are moving in an odd direction if i combine them…Please help me :frowning:

Anyone,please?
Look :
This is before : ImageShack - Best place for all of your image hosting and image sharing needs
This is after : ImageShack - Best place for all of your image hosting and image sharing needs

But as i said,if the parent is at 0,0,0 , it works perfectly :

Before : ImageShack - Best place for all of your image hosting and image sharing needs
After : ImageShack - Best place for all of your image hosting and image sharing needs

Hi,

I just had the same problem…
And I don’t know the cause…
However:

@script RequireComponent(MeshFilter)
@script RequireComponent(MeshRenderer)
function Start () {
[indent]

//Begin nearly-funny fix
var position = transform.position;
transform.position = Vector3.zero;
//End nearly-funny fix

var meshFilters = GetComponentsInChildren(MeshFilter);
var combine : CombineInstance[] = new CombineInstance[meshFilters.length];
for ( i = 0; i < meshFilters.length; i++){
[indent]
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
[/indent]
}
transform.GetComponent(MeshFilter).mesh = new Mesh();
transform.GetComponent(MeshFilter).mesh.CombineMeshes(combine);
transform.gameObject.active = true;

//Begin nearly-funny fix: Redux
transform.position = position;
//Fin

[/indent]
}

Should fix your problem. I’ve done the same.

Excuse the code if it has one or two things missing - I’m a C# man myself.

Good luck!

-JFFM

Yeah,thanks,i have later noticed the same fix.

Thanks for the anwser! :slight_smile: