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

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

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

        //apply the changes we made this can be slow. See documentation
        meshbaker.Apply();
    }
    void OnGUI()
    {
        GUILayout.Label("Time to bake textures: " + elapsedTime);
        if (GUILayout.Button("Combine textures & build combined mesh"))
        {
            MB2_MeshBaker    meshbaker    = target.GetComponent <MB2_MeshBaker>();
            MB2_TextureBaker textureBaker = target.GetComponent <MB2_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, true, false);

            meshbaker.Apply();
        }
    }
	void Start(){
		mbd = GetComponent<MB2_MeshBaker>(); 
		
		// instantiate 10k 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);
		mbd.Apply();
		
		objs = objsInCombined.ToArray();
		//start routine which will periodically add and delete objects
		StartCoroutine(largeNumber());
	}
Пример #4
0
    void Start()
    {
        mbd = GetComponent <MB2_MeshBaker>();

        // instantiate 10k 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);
        mbd.Apply();

        objs = objsInCombined.ToArray();
        //start routine which will periodically add and delete objects
        StartCoroutine(largeNumber());
    }
Пример #5
0
    IEnumerator largeNumber()
    {
        while (true)
        {
            yield return(new WaitForSeconds(1.5f));

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

            yield return(new WaitForSeconds(1.5f));

            //Add objects back
            mbd.AddDeleteGameObjects(objs, null);
            mbd.Apply(true, true, true, true, true, false, false, false);
        }
    }
Пример #6
0
    void Start()
    {
        //Add the objects to the combined mesh
        //Must have previously baked textures for these in the editor
        meshbaker.AddDeleteGameObjects(objsToCombine, null);

        //apply the changes we made this can be slow. See documentation
        meshbaker.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);
        worker1.animation.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
        worker1.animation.cullingType = AnimationCullingType.AlwaysAnimate;             //IMPORTANT
        worker1.animation.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);
        //apply the changes to the mesh
        skinnedMeshBaker.Apply();
    }