Beispiel #1
0
    void saveCombine()
    {
        GameObject [] go  = GameObject.FindGameObjectsWithTag("newobject");
        GameObject    ori = go[0];

        MeshFilter[] meshFilters = new MeshFilter[go.Length];
        for (int i = 0; i < go.Length; i++)
        {
            meshFilters[i] = go[i].GetComponent <MeshFilter>();
        }
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];
        for (int i = 0; i < meshFilters.Length; i++)
        {
            combine[i].mesh      = meshFilters[i].sharedMesh;
            combine[i].transform = ori.transform.worldToLocalMatrix * meshFilters[i].transform.localToWorldMatrix;
        }
        Base3D obj = new Base3D();

        obj.BaseObj     = new GameObject("Combined");
        obj.BaseObj.tag = "Combined";
        obj.BaseObj.AddComponent <MeshFilter>();
        obj.BaseObj.AddComponent <MeshRenderer>();
        obj.BaseObj.GetComponent <MeshFilter>().mesh = new Mesh();
        obj.BaseObj.GetComponent <MeshFilter>().mesh.MarkDynamic();
        obj.BaseObj.GetComponent <MeshRenderer>().material = ori.GetComponent <MeshRenderer>().material;
        obj.WireframeFlag = false;
        obj.BaseObj.transform.GetComponent <MeshFilter>().mesh = new Mesh();
        obj.BaseObj.transform.GetComponent <MeshFilter>().mesh.CombineMeshes(combine);

        Global.saveObj = obj;

        Destroy(obj.BaseObj);
    }
Beispiel #2
0
 public void Copy()
 {
     if (Global.objDict.ContainsKey(Global.SelectID))
     {
         Base3D obj = new Base3D();
         obj.BaseObj = new GameObject("newobject");
         obj.BaseObj.AddComponent <MeshFilter>();
         obj.BaseObj.AddComponent <MeshRenderer>();
         obj.BaseObj.GetComponent <MeshFilter>().mesh = Global.objDict[Global.SelectID].mesh;
         obj.RawVertices = new Vector3[Global.objDict[Global.SelectID].RawVertices.Length];
         obj.RawVertices.CopyTo(Global.objDict[Global.SelectID].RawVertices, 0);
         obj.BaseObj.GetComponent <MeshRenderer>().material.SetFloat("_Glossiness", 0.5f);
         //normals = new Vector3[vertices.Length];
         //Normalize(vertices, normals);
         //obj.mesh.normals = normals;
         obj.mesh.name = obj.Name;
         obj.BaseObj.AddComponent <MeshCollider>();
         obj.BaseObj.GetComponent <MeshCollider>().convex = true;
         obj.BaseObj.AddComponent <Rigidbody>();
         obj.BaseObj.GetComponent <Rigidbody>().useGravity  = false;
         obj.BaseObj.GetComponent <Rigidbody>().isKinematic = false;
         // obj.transform.parent = transform.transform;
         obj.transform.position   = transform.position;
         obj.transform.rotation   = Global.objDict[Global.SelectID].transform.rotation;
         obj.transform.localScale = Global.objDict[Global.SelectID].transform.localScale;
         Global.objDict.Add(obj.Id, obj);
         Debug.Log("selectID:" + Global.SelectID);
         Debug.Log("copyID:" + obj.Id);
     }
 }
Beispiel #3
0
    void mergerCombine()
    {
        GameObject ori = Global.objDict[int.Parse(Global.SelectIDGroup[0].ToString())].BaseObj;

        MeshFilter[] meshFilters = new MeshFilter[Global.SelectIDGroup.Count];
        for (int i = 0; i < Global.SelectIDGroup.Count; i++)
        {
            meshFilters[i] = Global.objDict[int.Parse(Global.SelectIDGroup[i].ToString())].BaseObj.GetComponent <MeshFilter>();
        }
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];
        for (int i = 0; i < meshFilters.Length; i++)
        {
            combine[i].mesh      = meshFilters[i].sharedMesh;
            combine[i].transform = ori.transform.worldToLocalMatrix * meshFilters[i].transform.localToWorldMatrix;//百度
        }

        Base3D obj = new Base3D();

        obj.BaseObj     = new GameObject("newobject");
        obj.BaseObj.tag = "newobject";
        obj.BaseObj.AddComponent <MeshFilter>();
        obj.BaseObj.AddComponent <MeshRenderer>();
        obj.BaseObj.GetComponent <MeshFilter>().mesh = new Mesh();
        obj.BaseObj.GetComponent <MeshFilter>().mesh.MarkDynamic();
        obj.BaseObj.GetComponent <MeshRenderer>().material = ori.GetComponent <MeshRenderer>().material;
        obj.WireframeFlag = false;
        obj.BaseObj.AddComponent <Rigidbody>();
        obj.BaseObj.GetComponent <Rigidbody>().useGravity      = false;
        obj.BaseObj.GetComponent <Rigidbody>().isKinematic     = false;
        obj.BaseObj.transform.GetComponent <MeshFilter>().mesh = new Mesh();
        obj.BaseObj.transform.GetComponent <MeshFilter>().mesh.CombineMeshes(combine);
        obj.BaseObj.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
        obj.BaseObj.transform.position   = ori.transform.position;
        obj.BaseObj.transform.rotation   = ori.transform.rotation;
        obj.BaseObj.AddComponent <MeshCollider>();
        obj.BaseObj.AddComponent <MeshCollider>().convex = true;

        Global.objDict.Add(obj.Id, obj);
        for (int i = 0; i < Global.SelectIDGroup.Count; i++)
        {
            Destroy(Global.objDict[int.Parse(Global.SelectIDGroup[i].ToString())].BaseObj);
            Global.objDict.Remove(Global.objDict[int.Parse(Global.SelectIDGroup[i].ToString())].BaseObj.GetInstanceID());
        }
        Global.SelectIDGroup.Clear();
    }
Beispiel #4
0
 public void Save()
 {
     if (Global.objDict.Count != 0)
     {
         GameObject        root        = Global.sceneSet[Global.sceneSet.Count - 1];
         MeshFilter[]      meshFilters = root.GetComponentsInChildren <MeshFilter>();
         CombineInstance[] combine     = new CombineInstance[meshFilters.Length];
         Matrix4x4         matrix      = root.transform.worldToLocalMatrix;
         for (int i = 0; i < meshFilters.Length; i++)
         {
             MeshFilter mf = meshFilters[i];
             combine[i].mesh      = mf.sharedMesh;
             combine[i].transform = matrix * mf.transform.localToWorldMatrix;
         }
         Mesh mesh = new Mesh();
         mesh.CombineMeshes(combine, false);
         Base3D obj = new Base3D();
         obj.BaseObj = new GameObject("Combined");
         obj.BaseObj.AddComponent <MeshFilter>();
         obj.BaseObj.AddComponent <MeshRenderer>();
         obj.BaseObj.GetComponent <MeshFilter>().mesh = mesh;
         obj.BaseObj.GetComponent <MeshRenderer>().material.SetFloat("_Glossiness", 0.5f);
         obj.mesh.name = obj.Name;
         obj.BaseObj.AddComponent <MeshCollider>();
         obj.BaseObj.GetComponent <MeshCollider>().convex    = true;
         obj.BaseObj.GetComponent <MeshCollider>().isTrigger = true;
         obj.BaseObj.AddComponent <Rigidbody>();
         obj.BaseObj.GetComponent <Rigidbody>().useGravity  = false;
         obj.BaseObj.GetComponent <Rigidbody>().isKinematic = false;
         obj.BaseObj.AddComponent <ModelEditor>();
         obj.BaseObj.GetComponent <ModelEditor>().enabled = false;
         obj.transform.parent     = root.transform;
         obj.transform.position   = root.transform.position;
         obj.transform.rotation   = root.transform.rotation;
         obj.transform.localScale = root.transform.localScale;
         Global.objDict.Add(obj.Id, obj);
         // print(obj.BaseObj.GetComponent<MeshFilter>().mesh.vertexCount);
         System.DateTime t = System.DateTime.Now;
         SaveSTL(Application.dataPath + "//Resources//", t.Year.ToString() + t.Month.ToString() + t.Day.ToString() + t.Hour.ToString() + t.Minute.ToString() + t.Second.ToString() + ".stl", obj.BaseObj.GetComponent <MeshFilter>().sharedMesh);
     }
 }
Beispiel #5
0
    public GameObject CombineObject(GameObject root)
    {
        MeshFilter[]      meshFilters = root.GetComponentsInChildren <MeshFilter>();
        CombineInstance[] combine     = new CombineInstance[meshFilters.Length];
        Matrix4x4         matrix      = root.transform.worldToLocalMatrix;

        for (int i = 0; i < meshFilters.Length; i++)
        {
            MeshFilter mf = meshFilters [i];
            combine[i].mesh      = mf.sharedMesh;
            combine[i].transform = matrix * mf.transform.localToWorldMatrix;
        }
        Base3D obj = new Base3D();

        obj.BaseObj = new GameObject("newobject");
        obj.BaseObj.AddComponent <MeshFilter>();
        obj.BaseObj.GetComponent <MeshFilter>().mesh.CombineMeshes(combine, true);
        obj.BaseObj.AddComponent <MeshRenderer>();
        obj.BaseObj.GetComponent <MeshRenderer>().material.SetFloat("_Glossiness", 0.0f);
        obj.BaseObj.GetComponent <MeshRenderer>().sharedMaterial.color = Color.white;
        obj.mesh.name = obj.Name;
        obj.BaseObj.AddComponent <Rigidbody>();
        obj.BaseObj.GetComponent <Rigidbody>().useGravity  = false;
        obj.BaseObj.GetComponent <Rigidbody>().isKinematic = false;
        obj.BaseObj.AddComponent <ModelEditor>();
        print(obj.BaseObj.GetComponent <MeshFilter>().mesh.vertexCount);
        obj.transform.parent     = Global.sceneSet[Global.sceneSet.Count - 1].transform;
        obj.transform.position   = root.transform.position;
        obj.transform.rotation   = root.transform.rotation;
        obj.transform.localScale = root.transform.localScale;
        Global.objDict.Add(obj.Id, obj);
        for (int i = 0; i < meshFilters.Length; i++)
        {
            Global.objDict.Remove(meshFilters[i].gameObject.GetInstanceID());
            Destroy(meshFilters[i].gameObject);
        }
        return(obj.BaseObj);
    }
Beispiel #6
0
    void Start()
    {
        MeshFilter[]      meshFilters = GetComponentsInChildren <MeshFilter> ();
        CombineInstance[] combine     = new CombineInstance[meshFilters.Length];
        Matrix4x4         matrix      = transform.worldToLocalMatrix;

        for (int i = 0; i < meshFilters.Length; i++)
        {
            MeshFilter mf = meshFilters [i];
            combine[i].mesh      = mf.sharedMesh;
            combine[i].transform = matrix * mf.transform.localToWorldMatrix;
        }
        Base3D obj = new Base3D();

        obj.BaseObj = new GameObject("newobject");
        obj.BaseObj.AddComponent <MeshFilter>();
        obj.BaseObj.AddComponent <MeshRenderer>();
        obj.BaseObj.GetComponent <MeshFilter>().mesh.CombineMeshes(combine, true);
        obj.BaseObj.GetComponent <MeshRenderer>().material.SetFloat("_Glossiness", 0.5f);
        obj.mesh.name = obj.Name;
        obj.BaseObj.AddComponent <MeshCollider>();
        obj.BaseObj.GetComponent <MeshCollider>().convex    = true;
        obj.BaseObj.GetComponent <MeshCollider>().isTrigger = true;
        obj.BaseObj.AddComponent <Rigidbody>();
        obj.BaseObj.GetComponent <Rigidbody>().useGravity  = false;
        obj.BaseObj.GetComponent <Rigidbody>().isKinematic = false;
        obj.BaseObj.AddComponent <ModelEditor>();
        obj.transform.parent     = Global.sceneSet[Global.sceneSet.Count - 1].transform;
        obj.transform.position   = transform.position;
        obj.transform.rotation   = transform.rotation;
        obj.transform.localScale = transform.localScale;
        Global.objDict.Add(obj.Id, obj);
        for (int i = 0; i < transform.childCount; i++)
        {
            Destroy(transform.GetChild(i).gameObject);
            Global.objDict.Remove(transform.GetChild(i).gameObject.GetInstanceID());
        }
    }
Beispiel #7
0
    public GameObject NewObject(GameObject copyObj)
    {
        Base3D obj = new Base3D();

        obj.BaseObj = new GameObject("newobject");
        obj.BaseObj.AddComponent <MeshFilter>();
        obj.BaseObj.AddComponent <MeshRenderer>();
        obj.BaseObj.GetComponent <MeshFilter>().sharedMesh = copyObj.GetComponent <MeshFilter>().mesh;
        obj.BaseObj.GetComponent <MeshRenderer>().material.SetFloat("_Glossiness", 0.0f);
        obj.BaseObj.GetComponent <MeshRenderer>().sharedMaterial.color = Color.white;
        obj.mesh.name = obj.Name;
        obj.BaseObj.AddComponent <Rigidbody>();
        obj.BaseObj.GetComponent <Rigidbody>().useGravity  = false;
        obj.BaseObj.GetComponent <Rigidbody>().isKinematic = false;
        obj.BaseObj.AddComponent <ModelEditor>();
        obj.BaseObj.AddComponent <FaceEditor>();
        obj.transform.parent     = Global.sceneSet[Global.sceneSet.Count - 1].transform;
        obj.transform.position   = copyObj.transform.position;
        obj.transform.rotation   = copyObj.transform.rotation;
        obj.transform.localScale = copyObj.transform.localScale;
        Global.objDict.Add(obj.Id, obj);
        return(obj.BaseObj);
    }
Beispiel #8
0
    private GameObject Copy(GameObject copyObj)
    {
        Base3D obj = new Base3D();

        obj.BaseObj = new GameObject("newobject");
        obj.BaseObj.AddComponent <MeshFilter>();
        obj.BaseObj.AddComponent <MeshRenderer>();
        obj.BaseObj.GetComponent <MeshFilter>().mesh = copyObj.GetComponent <MeshFilter>().mesh;
        obj.BaseObj.GetComponent <MeshRenderer>().material.SetFloat("_Glossiness", 0.5f);
        obj.mesh.name = obj.Name;
        obj.BaseObj.AddComponent <MeshCollider>();
        obj.BaseObj.GetComponent <MeshCollider>().convex    = true;
        obj.BaseObj.GetComponent <MeshCollider>().isTrigger = true;
        obj.BaseObj.AddComponent <Rigidbody>();
        obj.BaseObj.GetComponent <Rigidbody>().useGravity  = false;
        obj.BaseObj.GetComponent <Rigidbody>().isKinematic = false;
        obj.BaseObj.AddComponent <ModelEditor>();
        obj.transform.parent     = Global.sceneSet[Global.sceneSet.Count - 1].transform;
        obj.transform.position   = copyObj.transform.position;
        obj.transform.rotation   = copyObj.transform.rotation;
        obj.transform.localScale = copyObj.transform.localScale;
        Global.objDict.Add(obj.Id, obj);
        return(obj.BaseObj);
    }