Beispiel #1
0
        void InitBones()
        {
            BoneInfo[]       boneInfos = SharedData.skinningData.boneInfos;
            List <Transform> allTs     = new List <Transform>();

            GPUAnimUtils.GetAllChildren(srcBoneRoot, allTs);

            trDatas = new TRData[boneInfos.Length];
            for (int i = 0; i < trDatas.Length; i++)
            {
                TRData trData = new TRData();
                trData.name        = boneInfos[i].name;
                trData.bindPoseInv = boneInfos[i].bindPose.inverse;
                foreach (var t in allTs)
                {
                    if (t.name == trData.name)
                    {
                        trData.oriT = t;
                        break;
                    }
                }

                trDatas[i] = trData;
            }

            _pixelPerFrame = boneInfos.Length * 3;
        }
Beispiel #2
0
        /// <summary>
        /// 将除 mesh 节点,挂点(将其提到最顶级),rootMotion 之外的所有节点移除
        /// </summary>
        private void ProcessNode()
        {
            _rootMotionNode = transform.Find(Consts.ROOT_MOTION_NAME);

            List <Transform> allChildren = new List <Transform>();

            GPUAnimUtils.GetAllChildren(transform, allChildren);

            List <SkinnedMeshRenderer> smrs = new List <SkinnedMeshRenderer>();

            foreach (var node in allChildren)
            {
                if (node == transform)
                {
                    continue;
                }

                SkinnedMeshRenderer smr = node.GetComponent <SkinnedMeshRenderer>();
                if (smr != null)
                {
                    /*
                     *  调试代码,发布时把 if 去掉
                     *  (挂载的这个武器并不能使用模型的 Animation, 并且其 Bone 数量也为0,因此应该是用 MeshRenderer 而不是 SkinnedMeshRenderer)
                     */
                    if (node.name != "right_weapon")
                    {
                        // 某些 smr 不位于模型直接子节点,将其提升以避免被移除掉(显示不会受到影响)
                        if (node.parent != transform)
                        {
                            node.parent = transform;
                        }
                        smrs.Add(smr);
                        continue;
                    }
                }

                if (node == _rootMotionNode)
                {
                    continue;
                }

                bool isJoint = false;
                //foreach (var name in skinningData.jointNames)
                //{
                //    if (name == node.name)
                //    {
                //        node.parent = transform;
                //        isJoint = true;
                //        break;
                //    }
                //}

                if (!isJoint)
                {
                    // 不要使用 DestroyImmediate, 否则循环中的其它元素可能无法访问并且下面的 bsmr.Init 无法获取到 bones
                    Destroy(node.gameObject);
                }
            }

            // 原始的 SkinnedMeshRenderer 都创建对应的两种 Renderer
            foreach (var smr in smrs)
            {
                GPURendererRes res = GPUSkinRuntimeResMgr.Instance.GetOrCreateRes(smr, skinningData);
                _bakedGPUAnimation.AddMeshRenderer(res);
                _GPUAnimation.AddMeshRenderer(res);
                DestroyImmediate(smr);
            }

            Animation oriAnimation = gameObject.GetComponent <Animation>();

            if (oriAnimation != null)
            {
                DestroyImmediate(oriAnimation);
            }

            // 初始化绑点
            //_jointTrans = new Transform[skinningData.jointNames.Length];
            //for (int i = 0; i < _jointTrans.Length; i++)
            //{
            //    Transform t = transform.Find(skinningData.jointNames[i]);
            //    if (t == null)
            //    {
            //        Debug.LogErrorFormat("can not find join {0}", skinningData.jointNames[i]);
            //        return;
            //    }

            //    _jointTrans[i] = t;
            //}

            _bakedGPUAnimation.SetJointTransforms(_jointTrans);
            _GPUAnimation.SetJointTransforms(_jointTrans);
        }