Esempio n. 1
0
	// breaks a pb_object into a zillion* faces
	public static GameObject[] ExplodeObject(pb_Object pb)
	{
		// disable 'ze donor
		pb.gameObject.SetActive(false);
		
		GameObject[] pieces = new GameObject[pb.faces.Length];
		
		// extract mesh and material information for every face, and assign it to a gameobject
		for(int i = 0; i < pieces.Length; i++)
		{
			Mesh m = new Mesh();
			m.vertices 	= pb.GetVertices(pb.faces[i]);
			m.triangles	= new int[6] {0,1,2, 1,3,2};
			m.normals  	= pb.GetNormals(pb.faces[i]);
			m.uv	  	= pb.GetUVs(pb.faces[i]);
			m.RecalculateBounds();

			GameObject go = new GameObject();
			go.transform.position = pb.transform.position + pb_Math.PlaneNormal(m.vertices).normalized * .3f;
			go.transform.localRotation = pb.transform.localRotation;
			
			go.AddComponent<MeshFilter>().sharedMesh = m;
			go.AddComponent<MeshRenderer>().sharedMaterial = pb.GetMaterial(pb.faces[i]);

			pieces[i] = go;
		}

		return pieces;
	}
Esempio n. 2
0
    // breaks a pb_object into a zillion* faces
    public static GameObject[] ExplodeObject(pb_Object pb)
    {
        // disable 'ze donor
        pb.gameObject.SetActive(false);

        GameObject[] pieces = new GameObject[pb.faces.Length];

        // extract mesh and material information for every face, and assign it to a gameobject
        for (int i = 0; i < pieces.Length; i++)
        {
            Mesh m = new Mesh();
            m.vertices  = pb.GetVertices(pb.faces[i]);
            m.triangles = new int[6] {
                0, 1, 2, 1, 3, 2
            };
            m.normals = pb.GetNormals(pb.faces[i]);
            m.uv      = pb.GetUVs(pb.faces[i]);
            m.RecalculateBounds();

            GameObject go = new GameObject();
            go.transform.position      = pb.transform.position + pb_Math.PlaneNormal(m.vertices).normalized * .3f;
            go.transform.localRotation = pb.transform.localRotation;

            go.AddComponent <MeshFilter>().sharedMesh       = m;
            go.AddComponent <MeshRenderer>().sharedMaterial = pb.GetMaterial(pb.faces[i]);

            pieces[i] = go;
        }

        return(pieces);
    }