public void SetMesh(Asset asset) { FaceMeshAsset avatarFace = asset as FaceMeshAsset; if (avatarFace == null) { throw new Exception("Could not convert asset from Repo to FaceMeshAsset."); } mMesh = avatarFace.Mesh; mUvShellNameToIndex.Clear(); /* * Create a list of UV shells ( A submesh maps to one UV shell ) * and populate the corresponding frameSequence and currentFrame arrays */ int uvShellCount = avatarFace.UvShellCount; mUvShells = new UvShell[uvShellCount]; mCurrentFrames = new int[uvShellCount]; mFrameSequence = new int[uvShellCount][]; mGridSize = new Vector2[uvShellCount]; mCellSize = new Vector2[uvShellCount]; mNumberOfCells = new int[uvShellCount]; for (int x = 0; x < uvShellCount; x++) { mUvShells[x] = new UvShell(mMesh, x); mCurrentFrames[x] = -1; // OFF mGridSize[x] = avatarFace.GetUvGridDimensions(x); mCellSize[x] = new Vector2(1.0f / mGridSize[x].x, 1.0f / mGridSize[x].y); mNumberOfCells[x] = (int)(mGridSize[x].x * mGridSize[x].y); mUvShellNameToIndex.Add(avatarFace.GetUvShellName(x), x); } /* * Combine all submeshes into one mesh ( i.e. create a new mesh ) */ Mesh newMesh = new Mesh(); newMesh.vertices = mMesh.vertices; newMesh.triangles = mMesh.triangles; newMesh.uv = mMesh.uv; newMesh.normals = mMesh.normals; newMesh.RecalculateBounds(); mMesh = newMesh; mMeshFilter.mesh = newMesh; /* * Set the atlas space for the UV shells */ for (int x = 0; x < mUvShells.Length; ++x) { mUvShells[x].Atlas = mTexturePalette.GetTextureZoneUvArea(avatarFace.GetUvShellTextureZoneName(x)); } /* Update Uvs */ mNewUvs = mMesh.uv; for (int x = 0; x < mUvShells.Length; ++x) { UpdateUvShell(mUvShells[x]); } mMesh.uv = mNewUvs; mUvsAreDirty = false; /* Update Material */ Material avatarMaterial = AvatarEntity.AvatarMaterial; avatarMaterial.mainTexture = mMeshRenderer.materials[0].mainTexture; mMeshRenderer.materials = new Material[] { avatarMaterial }; }
/* * Update a UvShell Object and put the result in mNewUvs */ private void UpdateUvShell(UvShell shell) { shell.UpdateUvs(mNewUvs); mUvsAreDirty = true; }