Ejemplo n.º 1
0
        private void AddMeshVertex2Generate(SkinnedMeshRenderer[] meshRender,
                                            Transform[] boneTransform,
                                            Matrix4x4[] bindPose)
        {
            boneCount          = boneTransform.Length;
            textureBlockWidth  = 4;
            textureBlockHeight = boneCount;
            for (int i = 0; i != meshRender.Length; ++i)
            {
                Mesh m = meshRender[i].sharedMesh;
                if (m == null)
                {
                    continue;
                }

                int nameCode = meshRender[i].name.GetHashCode();
                if (generateVertexCachePool.ContainsKey(nameCode))
                {
                    continue;
                }

                AnimationInstancingMgr.VertexCache vertexCache = new AnimationInstancingMgr.VertexCache();
                generateVertexCachePool[nameCode] = vertexCache;
                vertexCache.nameCode = AnimationInstancingMgr.getVertexName(meshRender[i]);                 // nameCode;
                vertexCache.bonePose = boneTransform;
                vertexCache.bindPose = bindPose;
                break;
            }
        }
Ejemplo n.º 2
0
        public void Attach(string boneName, AnimationInstancing attachment)
        {
            int index    = -1;
            int hashBone = boneName.GetHashCode();

            for (int i = 0; i != allTransforms.Length; ++i)
            {
                if (allTransforms[i].name.GetHashCode() == hashBone)
                {
                    index = i;
                    break;
                }
            }
            Debug.Assert(index >= 0);
            if (index < 0)
            {
                Debug.LogError("Can't find the bone.");
                return;
            }

            attachment.parentInstance = this;

//			string vertexName = lodInfo[0].skinnedMeshRenderer[0].name.GetHashCode() +"_" + lodInfo[0].skinnedMeshRenderer[0].sharedMaterial.name.GetHashCode() + "_0";
            AnimationInstancingMgr.VertexCache parentCache = AnimationInstancingMgr.Instance.FindVertexCache(AnimationInstancingMgr.getVertexName(lodInfo[0].skinnedMeshRenderer[0]));
            listAttachment.Add(attachment);

            int skinnedMeshRenderCount = attachment.lodInfo[0].skinnedMeshRenderer.Length;
//			int nameCode = attachment.lodInfo[0].meshRenderer[0].name.GetHashCode() + boneName.GetHashCode();
            string nameCode = AnimationInstancingMgr.getVertexName(attachment.lodInfo[0].meshRenderer[0]);

            AnimationInstancingMgr.VertexCache cache = AnimationInstancingMgr.Instance.FindVertexCache(nameCode);
            // if we can reuse the VertexCache, we don't need to create one
            if (cache != null && cache.boneTextureIndex >= 0 &&
                cache.boneTextureIndex == parentCache.boneTextureIndex &&
                cache.boneIndex[0].x == index)
            {
                for (int i = 0; i != attachment.lodInfo.Length; ++i)
                {
                    LodInfo info = attachment.lodInfo[i];
                    for (int j = 0; j != info.meshRenderer.Length; ++j)
                    {
                        nameCode = AnimationInstancingMgr.getVertexName(info.meshRenderer[j], boneName.GetHashCode());
                        cache    = AnimationInstancingMgr.Instance.FindVertexCache(nameCode);
                        info.vertexCacheList[info.skinnedMeshRenderer.Length + j] = cache;
                    }
                }
                return;
            }

            AnimationInstancingMgr.Instance.AddMeshVertex(attachment,
                                                          attachment.lodInfo,
                                                          null,
                                                          null,
                                                          attachment.bonePerVertex,
                                                          boneName);

            for (int i = 0; i != attachment.lodInfo.Length; ++i)
            {
                LodInfo info = attachment.lodInfo[i];
                for (int j = 0; j != info.meshRenderer.Length; ++j)
                {
                    cache = info.vertexCacheList[info.skinnedMeshRenderer.Length + j];
                    Debug.Assert(cache != null);
                    if (cache == null)
                    {
                        Debug.LogError("Can't find the VertexCache.");
                        continue;
                    }
                    Debug.Assert(cache.boneTextureIndex < 0 || cache.boneIndex[0].x != index);

                    AnimationInstancingMgr.Instance.BindAttachment(parentCache, info.meshFilter[j].sharedMesh, index);
                    AnimationInstancingMgr.Instance.SetupAdditionalData(cache);
                    cache.boneTextureIndex = parentCache.boneTextureIndex;
                }
            }
        }