Ejemplo n.º 1
0
    void Start()
    {
        //Add the objects to the combined mesh
        //Must have previously baked textures for these in the editor
        meshbaker.AddDeleteGameObjects(objsToMove, null, true);
        meshbaker.AddDeleteGameObjects(new GameObject[] { objWithChangingUVs }, null, true);

        MeshFilter mf = objWithChangingUVs.GetComponent <MeshFilter>();

        m   = mf.sharedMesh;
        uvs = m.uv;

        //apply the changes we made this can be slow. See documentation
        meshbaker.Apply();

        //same with multi mesh baker
        multiMeshBaker.AddDeleteGameObjects(objsToMove, null, true);
        multiMeshBaker.AddDeleteGameObjects(new GameObject[] { objWithChangingUVs }, null, true);

        mf  = objWithChangingUVs.GetComponent <MeshFilter>();
        m   = mf.sharedMesh;
        uvs = m.uv;

        multiMeshBaker.Apply();
    }
Ejemplo n.º 2
0
 void Start()
 {
     //Add the objects to the combined mesh
     //Must have previously baked textures for these in the editor
     meshbaker.AddDeleteGameObjects(objsToCombine, null, true);
     //apply the changes we made this can be slow. See documentation
     meshbaker.Apply();
 }
Ejemplo n.º 3
0
 void Start()
 {
     //initial bake
     GameObject[] objs = new GameObject[clothingAndBodyPartsBareTorso.Length];
     for (int i = 0; i < clothingAndBodyPartsBareTorso.Length; i++)
     {
         objs[i] = clothingAndBodyPartsBareTorso[i].gameObject;
     }
     meshBaker.ClearMesh();
     meshBaker.AddDeleteGameObjects(objs, null, true);
     meshBaker.Apply();
 }
Ejemplo n.º 4
0
    void Start()
    {
        mbd = GetComponentInChildren <MB3_MeshBaker>();

        // instantiate game objects
        int dim = 25;

        GameObject[] gos = new GameObject[dim * dim];
        for (int i = 0; i < dim; i++)
        {
            for (int j = 0; j < dim; j++)
            {
                GameObject go = (GameObject)Instantiate(prefab);
                gos[i * dim + j]      = go.GetComponentInChildren <MeshRenderer>().gameObject;
                go.transform.position = (new Vector3(9f * i, 0, 9f * j));
                //put every third object in a list so we can add and delete it later
                if ((i * dim + j) % 3 == 0)
                {
                    objsInCombined.Add(gos[i * dim + j]);
                }
            }
        }
        //add objects to combined mesh
        mbd.AddDeleteGameObjects(gos, null, true);
        mbd.Apply();

        objs = objsInCombined.ToArray();
        //start routine which will periodically add and delete objects
        StartCoroutine(largeNumber());
    }
    void OnGUI()
    {
        GUILayout.Label("Time to bake textures: " + elapsedTime);
        if (GUILayout.Button("Combine textures & build combined mesh"))
        {
            MB3_MeshBaker    meshbaker    = target.GetComponent <MB3_MeshBaker>();
            MB3_TextureBaker textureBaker = target.GetComponent <MB3_TextureBaker>();

            //These can be assets configured at runtime or you can create them
            // on the fly like this
            textureBaker.textureBakeResults = ScriptableObject.CreateInstance <MB2_TextureBakeResults>();
            textureBaker.resultMaterial     = new Material(Shader.Find("Diffuse"));

            float t1 = Time.realtimeSinceStartup;
            textureBaker.CreateAtlases();
            elapsedTime = Time.realtimeSinceStartup - t1;

            meshbaker.ClearMesh();             //only necessary if your not sure whats in the combined mesh
            meshbaker.textureBakeResults = textureBaker.textureBakeResults;
            //Add the objects to the combined mesh
            meshbaker.AddDeleteGameObjects(textureBaker.GetObjectsToCombine().ToArray(), null);

            meshbaker.Apply();
        }
    }
	void Start(){
		mbd = GetComponentInChildren<MB3_MeshBaker>(); 
		
		// instantiate game objects
		int dim = 25;
		GameObject[] gos = new GameObject[dim * dim];
		for (int i = 0; i < dim; i++){
			for (int j = 0; j < dim; j++){
				GameObject go = (GameObject) Instantiate(prefab);
				gos[i*dim + j] = go.GetComponentInChildren<MeshRenderer>().gameObject;
				go.transform.position = (new Vector3(9f*i,0,9f * j));
				//put every third object in a list so we can add and delete it later
				if ((i*dim + j) % 3 == 0){
					objsInCombined.Add(gos[i*dim + j]);
				}
			}
		}
		//add objects to combined mesh
		mbd.AddDeleteGameObjects(gos, null, true);
		mbd.Apply();
		
		objs = objsInCombined.ToArray();
		//start routine which will periodically add and delete objects
		StartCoroutine(largeNumber());
	}
    IEnumerator combineMesh(GameObject[] meshes, int index, string combiner, Transform parent, System.Action <GameObject> action)
    {
        meshbaker.AddDeleteGameObjects(meshes, null, false);
        meshbaker.Apply();
        yield return(new WaitForEndOfFrame());

        int deleteSteps = 10;

        for (int i = 0; i < meshes.Length; i += deleteSteps)
        {
            for (int j = 0; j < deleteSteps; j++)
            {
                if (i + j < meshes.Length)
                {
                    Destroy(meshes [i + j]);
                }
            }
            yield return(new WaitForEndOfFrame());
        }

        GameObject meshObjectChild = GameObject.Find(combiner).transform.GetChild(0).gameObject;
        GameObject generatedObj    = GameObject.Instantiate(meshObjectChild);

        generatedObj.GetComponent <MeshFilter> ().mesh     = meshObjectChild.GetComponent <MeshFilter> ().mesh;
        generatedObj.AddComponent <MeshCollider> ().convex = false;
        generatedObj.name             = meshes.Length + " combined meshes";
        generatedObj.transform.parent = parent;
        meshbaker.DestroyMesh();
        action(generatedObj);
    }
Ejemplo n.º 8
0
    IEnumerator largeNumber()
    {
        while (true)
        {
            yield return(new WaitForSeconds(1.5f));

            //Delete every third object
            mbd.AddDeleteGameObjects(null, objs, true);
            mbd.Apply();

            yield return(new WaitForSeconds(1.5f));

            //Add objects back
            mbd.AddDeleteGameObjects(objs, null, true);
            mbd.Apply();
        }
    }
    void Start()
    {
        //To demonstrate lets add a character to the combined mesh
        GameObject worker1 = (GameObject)Instantiate(workerPrefab);

        worker1.transform.position = new Vector3(1.31f, 0.985f, -0.25f);
        Animation anim = worker1.GetComponent <Animation>();

        anim.wrapMode = WrapMode.Loop;
        //IMPORTANT set the culling type to something other than renderer. Animations may not play
        //if animation.cullingType is left on BasedOnRenderers. This appears to be a bug in Unity
        //the animation gets confused about the bounds if the skinnedMeshRenderer is changed
        anim.cullingType = AnimationCullingType.AlwaysAnimate;                 //IMPORTANT
        anim.Play("run");

        //create an array with everything we want to add
        //It is important to add the gameObject with the Renderer/mesh attached
        GameObject[] objsToAdd = new GameObject[1] {
            worker1.GetComponentInChildren <SkinnedMeshRenderer>().gameObject
        };

        //add the objects. This will disable the renderers on the source objects
        skinnedMeshBaker.AddDeleteGameObjects(objsToAdd, null, true);
        //apply the changes to the mesh
        skinnedMeshBaker.Apply();
    }
    IEnumerator TestScript()
    {
        Debug.Log("Test 1 adding 0,1,2");
        GameObject[] a2 = new GameObject[] { g[0], g[1], g[2] };
        meshBaker.AddDeleteGameObjects(a2, null, true);
        meshBaker.Apply();
        meshBaker.meshCombiner.CheckIntegrity();
        yield return(new WaitForSeconds(3f));

        Debug.Log("Test 2 remove 1 and add 3,4,5");
        GameObject[] d1 = new GameObject[] { g[1] };
        a2 = new GameObject[] { g[3], g[4], g[5] };
        meshBaker.AddDeleteGameObjects(a2, d1, true);
        meshBaker.Apply();
        meshBaker.meshCombiner.CheckIntegrity();
        yield return(new WaitForSeconds(3f));

        Debug.Log("Test 3 remove 0,2,5 and add 1");
        d1 = new GameObject[] { g[3], g[4], g[5] };
        a2 = new GameObject[] { g[1] };
        meshBaker.AddDeleteGameObjects(a2, d1, true);
        meshBaker.Apply();
        meshBaker.meshCombiner.CheckIntegrity();
        yield return(new WaitForSeconds(3f));

        Debug.Log("Test 3 remove all remaining");
        d1 = new GameObject[] { g[0], g[1], g[2] };
        meshBaker.AddDeleteGameObjects(null, d1, true);
        meshBaker.Apply();
        meshBaker.meshCombiner.CheckIntegrity();
        yield return(new WaitForSeconds(3f));

        Debug.Log("Test 3 add all");
        meshBaker.AddDeleteGameObjects(g, null, true);
        meshBaker.Apply();
        meshBaker.meshCombiner.CheckIntegrity();
        yield return(new WaitForSeconds(1f));

        Debug.Log("Done");
    }
Ejemplo n.º 11
0
    void OnBuiltAtlasesSuccess()
    {
        Debug.Log("Calling success callback. baking meshes");
        MB3_MeshBaker    meshbaker    = target.GetComponentInChildren <MB3_MeshBaker>();
        MB3_TextureBaker textureBaker = target.GetComponent <MB3_TextureBaker>();

        //elapsedTime = Time.realtimeSinceStartup - t1;

        if (result.isFinished &&
            result.success)
        {
            meshbaker.ClearMesh(); //only necessary if your not sure whats in the combined mesh
            meshbaker.textureBakeResults = textureBaker.textureBakeResults;
            //Add the objects to the combined mesh
            meshbaker.AddDeleteGameObjects(textureBaker.GetObjectsToCombine().ToArray(), null, true);
            meshbaker.Apply();
        }
        Debug.Log("Completed baking textures on frame " + Time.frameCount);
    }
Ejemplo n.º 12
0
    void OnGUI()
    {
        GUILayout.Label("Time to bake textures: " + elapsedTime);
        if (GUILayout.Button("Combine textures & build combined mesh all at once"))
        {
            MB3_MeshBaker    meshbaker    = target.GetComponentInChildren <MB3_MeshBaker>();
            MB3_TextureBaker textureBaker = target.GetComponent <MB3_TextureBaker>();

            //These can be assets configured at runtime or you can create them
            // on the fly like this
            textureBaker.textureBakeResults = ScriptableObject.CreateInstance <MB2_TextureBakeResults>();
            textureBaker.resultMaterial     = new Material(Shader.Find(GetShaderNameForPipeline()));

            float t1 = Time.realtimeSinceStartup;
            textureBaker.CreateAtlases();
            elapsedTime = Time.realtimeSinceStartup - t1;

            meshbaker.ClearMesh();             //only necessary if your not sure whats in the combined mesh
            meshbaker.textureBakeResults = textureBaker.textureBakeResults;

            //Add the objects to the combined mesh
            meshbaker.AddDeleteGameObjects(textureBaker.GetObjectsToCombine().ToArray(), null, true);

            meshbaker.Apply();
        }

        if (GUILayout.Button("Combine textures & build combined mesh using coroutine"))
        {
            Debug.Log("Starting to bake textures on frame " + Time.frameCount);
            MB3_TextureBaker textureBaker = target.GetComponent <MB3_TextureBaker>();

            //These can be assets configured at runtime or you can create them
            // on the fly like this
            textureBaker.textureBakeResults = ScriptableObject.CreateInstance <MB2_TextureBakeResults>();
            textureBaker.resultMaterial     = new Material(Shader.Find(GetShaderNameForPipeline()));

            //register an OnSuccess function to be called when texture baking is complete
            textureBaker.onBuiltAtlasesSuccess = new MB3_TextureBaker.OnCombinedTexturesCoroutineSuccess(OnBuiltAtlasesSuccess);
            StartCoroutine(textureBaker.CreateAtlasesCoroutine(null, result, false, null, .01f));
        }
    }
Ejemplo n.º 13
0
    IEnumerator combineMesh(GameObject[] meshes, int iteration, string roomId, Transform parent, System.Action <GameObject> action)
    {
        meshbaker.AddDeleteGameObjects(meshes, null, false);
        meshbaker.Apply();
        yield return(new WaitForEndOfFrame());

        int deleteSteps = 10;

        for (int i = 0; i < meshes.Length; i += deleteSteps)
        {
            for (int j = 0; j < deleteSteps; j++)
            {
                if (i + j < meshes.Length)
                {
                    Destroy(meshes [i + j]);
                }
            }
            yield return(new WaitForEndOfFrame());
        }

        //room-N0 merge iteration 1
        // CombinedMesh-room-N0-mesh
        string searchName = "CombinedMesh-" + roomId + "-mesh";

        print(searchName);
        GameObject meshObject = GameObject.Find(searchName);
        //meshObject.name = threadId;

        GameObject meshObjectChild = meshObject.transform.GetChild(0).gameObject;
        GameObject generatedObj    = GameObject.Instantiate(meshObjectChild);

        generatedObj.GetComponent <MeshFilter> ().mesh     = meshObjectChild.GetComponent <MeshFilter> ().mesh;
        generatedObj.AddComponent <MeshCollider> ().convex = false;

        Destroy(meshObject);
        generatedObj.name             = meshes.Length + " combined meshes";
        generatedObj.transform.parent = parent;
        meshbaker.DestroyMesh();
        action(generatedObj);
    }
    void ChangeOutfit(Renderer[] outfit)
    {
        //collect the meshes we will be removing
        List <GameObject> objectsWeAreRemoving = new List <GameObject>();

        foreach (GameObject item in meshBaker.meshCombiner.GetObjectsInCombined())
        {
            Renderer r             = item.GetComponent <Renderer>();
            bool     foundInOutfit = false;
            for (int i = 0; i < outfit.Length; i++)
            {
                if (r == outfit[i])
                {
                    foundInOutfit = true;
                    break;
                }
            }
            if (!foundInOutfit)
            {
                objectsWeAreRemoving.Add(r.gameObject);
                Debug.Log("Removing " + r.gameObject);
            }
        }

        //Now collect the meshes we will be adding
        List <GameObject> objectsWeAreAdding = new List <GameObject>();

        for (int i = 0; i < outfit.Length; i++)
        {
            if (!meshBaker.meshCombiner.GetObjectsInCombined().Contains(outfit[i].gameObject))
            {
                objectsWeAreAdding.Add(outfit[i].gameObject);
                Debug.Log("Adding " + outfit[i].gameObject);
            }
        }

        meshBaker.AddDeleteGameObjects(objectsWeAreAdding.ToArray(), objectsWeAreRemoving.ToArray(), true);
        meshBaker.Apply();
    }
    void Start()
    {
        mbd = GetComponentInChildren <MB3_MeshBaker>();

        // instantiate game objects
        int dim = 25;

        GameObject[] gos = new GameObject[dim * dim];
        for (int i = 0; i < dim; i++)
        {
            for (int j = 0; j < dim; j++)
            {
                GameObject go = (GameObject)Instantiate(prefab);
                gos[i * dim + j] = go.GetComponentInChildren <MeshRenderer>().gameObject;
                float randx = Random.Range(-4f, 4f);
                float randz = Random.Range(-4f, 4f);
                go.transform.position = (new Vector3(9f * i + randx, 0, 9f * j + randz));
                float randrot = Random.Range(0, 360);
                go.transform.rotation = Quaternion.Euler(0, randrot, 0);
                Vector3 randscale = Vector3.one + Vector3.one * GaussianValue() * .15f;
                go.transform.localScale = randscale;
                //put every third object in a list so we can add and delete it later
                if ((i * dim + j) % 3 == 0)
                {
                    objsInCombined.Add(gos[i * dim + j]);
                }
            }
        }
        //add objects to combined mesh
        mbd.AddDeleteGameObjects(gos, null, true);
        mbd.Apply();

        objs = objsInCombined.ToArray();
        //start routine which will periodically add and delete objects
        StartCoroutine(largeNumber());
    }
 public void Start()
 {
     // Bake the mesh.
     meshBaker.AddDeleteGameObjects(meshBaker.GetObjectsToCombine().ToArray(), null, true);
     meshBaker.Apply();
 }