Ejemplo n.º 1
0
        //public ResId getOrRegMeshId(SkinnedMeshRenderer meshRend, Transform skeletonRoot){
        public void tryRegisterMeshSkeleton(MeshStorageKey meshKey, SkinnedMeshRenderer meshRend, Transform skeletonRoot)
        {
            Sanity.nullCheck(meshKey.mesh, "mesh cannot be null");

            //var meshKey = buildMeshKey(meshRend, true);
            //TODO - this needs to be moved into a subroutine of SkeletonRepository
            if (!meshDefaultSkeletonData.ContainsKey(meshKey))
            {
                var rootTransform = skeletonRoot;                //JsonSkeletonBuilder.findSkeletonRoot(meshRend);
                if (!rootTransform)
                {
                    rootTransform = JsonSkeletonBuilder.findSkeletonRoot(meshRend);
                }
                if (!rootTransform)
                {
                    throw new System.ArgumentException(
                              string.Format("Could not find skeleton root transform for {0}", meshRend));
                }

                var boneNames = meshRend.bones.Select((arg) => arg.name).ToList();

                var meshNode    = Utility.getSrcPrefabAssetObject(meshRend.gameObject.transform, false);
                var defaultData = new MeshDefaultSkeletonData(rootTransform, meshNode, boneNames);
                meshDefaultSkeletonData.Add(meshKey, defaultData);

                registerSkeleton(rootTransform, false);
            }

            //return getOrRegMeshId(meshKey, meshRend.gameObject, mesh);
        }
Ejemplo n.º 2
0
        public ResId registerSkeleton(Transform rootTransform, bool findPrefab)
        {
            if (findPrefab)
            {
                rootTransform = Utility.getSrcPrefabAssetObject(rootTransform, false);
            }

            JsonSkeleton skel = findSkeleton(rootTransform);

            if (skel != null)
            {
                var testId = findSkeletonId(rootTransform);
                Sanity.check(testId == skel.id, "ID mismatch within skeleton registry");
                return(skel.id);
            }

            /* if (jsonSkeletons.TryGetValue(rootTransform, out skel))
             *      return skel.id;*/

            var newSkel = JsonSkeletonBuilder.buildFromRootTransform(rootTransform);
            var newId   = ResId.fromObjectIndex(skeletons.Count);          //ResId.fromObjectIndex(jsonSkeletons.Count);

            Sanity.check(skeletons.Count == sortedSkelIds.Count, "Skeleton id and skeleton count mismatch");

            newSkel.id = newId;

            //jsonSkeletons.Add(rootTransform, newSkel);
            skelIds.Add(rootTransform, newId);
            skeletons.Add(newId, newSkel);
            sortedSkelIds.Add(newId);
            jsonSkeletonRootTransforms.Add(newSkel.id, rootTransform);

            return(newSkel.id);
        }