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;
            }
        }
 void Clear()
 {
     AnimationInstancingMgr.GetInstance().Clear();
     foreach (var obj in m_objs)
     {
         GameObject gameObj = obj as GameObject;
         Destroy(gameObj);
     }
 }
예제 #3
0
 private void OnDestroy()
 {
     if (!AnimationInstancingMgr.IsDestroy())
     {
         AnimationInstancingMgr.Instance.RemoveInstance(this);
     }
     if (parentInstance != null)
     {
         parentInstance.Deattach(this);
         parentInstance = null;
     }
 }
예제 #4
0
        public void clear()
        {
            if (!AnimationInstancingMgr.IsDestroy())
            {
                AnimationInstancingMgr.Instance.RemoveInstance(this);
                AnimationInstancingMgr.Instance.RemoveMeshVertex(this, lodInfo);
            }
            if (parentInstance != null)
            {
                parentInstance.Deattach(this);
                parentInstance = null;
            }

            Stop();
//			playSpeed = 1.0f;
//			lodFrequencyCount = 0;
        }
        void CreateObjInstancing()
        {
            //LoadAB();
            Vector3 pos   = new Vector3();
            int     width = (int)UnityEngine.Mathf.Sqrt((int)InstancingCount);

            for (int i = 0; i != InstancingCount; ++i)
            {
                GameObject prefab     = m_instancingList[Random.Range(0, m_instancingList.Length)];
                GameObject obj        = AnimationInstancingMgr.GetInstance().CreateInstance(prefab);
                GameObject attachment = null;
                if (m_testAttachment != null)
                {
                    attachment = AnimationInstancingMgr.GetInstance().CreateInstance(m_testAttachment);
                }

                Transform trans = obj.GetComponent <Transform>();
                trans.SetPositionAndRotation(pos, Quaternion.identity);
                //trans.Rotate(new Vector3(0, 45, 0));
                pos.x += 1.5f;
                if (pos.x > width * 1.5f)
                {
                    pos.x  = 0.0f;
                    pos.z += 1.5f;
                }
                AnimationInstancing script = obj.GetComponent <AnimationInstancing>();
                //script.PlayAnimation(Random.Range(0, script.m_aniInfo.Count));
                AnimationInstancing attachmentScript = null;
                if (attachment)
                {
                    attachmentScript = GetComponent <AnimationInstancing>();
                }
                StartCoroutine(RandomPlayAnimation(script, attachmentScript));
                //StartCoroutine(RandomPlayAnimation(script));
                m_objs.Add(obj);
            }
        }
예제 #6
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;
                }
            }
        }