Esempio n. 1
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);
        }
Esempio n. 2
0
        public AnimationSampler(Animator origAnimator, JsonSkeleton skeleton)
        {
            if (!origAnimator)
            {
                throw new System.ArgumentNullException();
            }
            spawnedAnimator = GameObject.Instantiate(origAnimator);
            if (!spawnedAnimator)
            {
                throw new System.Exception("Instantiating of original object failed while sampling animation");
            }

            transformRoot = spawnedAnimator.transform;

            targetTransforms = Utility.findNamedTransforms(
                skeleton.bones.Select((arg) => arg.name).ToList(),
                transformRoot);

            var guidName = System.Guid.NewGuid().ToString("N");
            var animControllerBaseAssetPath = string.Format("Assets/tmp-remapController-{0}.controller", guidName);

            Debug.LogFormat("guid: {0}, basePath: {1}", guidName, animControllerBaseAssetPath);
            animControllerPath = AssetDatabase.GenerateUniqueAssetPath(animControllerBaseAssetPath);
            Debug.LogFormat("generatedPath: {0}", animControllerPath);

            samplingController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(animControllerPath);
            var stateMachine = samplingController.layers[0].stateMachine;

            stateName = "clip";
            state     = samplingController.layers[0].stateMachine.AddState(stateName);

            spawnedAnimator.runtimeAnimatorController = samplingController;
        }
Esempio n. 3
0
        public static JsonSkeleton buildFromRootTransform(Transform prefabTransform)
        {
            var result  = new JsonSkeleton();
            var builder = new JsonSkeletonBuilder();

            builder.buildFromTransform(result, prefabTransform);
            return(result);
        }
Esempio n. 4
0
        public static JsonSkeleton buildFromPrefabRoot(GameObject prefabRoot)
        {
            var result  = new JsonSkeleton();
            var builder = new JsonSkeletonBuilder();

            builder.build(result, prefabRoot);
            return(result);
        }
Esempio n. 5
0
        public static JsonSkeleton buildFromSkinMesh(SkinnedMeshRenderer meshRend)
        {
            var result  = new JsonSkeleton();
            var builder = new JsonSkeletonBuilder();

            builder.build(result, new SkinnedMeshRenderer[] { meshRend });
            return(result);
        }
Esempio n. 6
0
        protected void buildFromTransform(JsonSkeleton result, Transform skeletonRoot)
        {
            if (!skeletonRoot)
            {
                throw new System.ArgumentNullException("skeletonRoot");
            }

            var transformIds = gatherIds(skeletonRoot);

            Debug.LogFormat("Transofrm skeleton:");
            printSkeleton(transformIds);

            result.clear();
            result.assignFrom(skeletonRoot, transformIds);
            result.name = findSkeletonName(skeletonRoot);
        }
Esempio n. 7
0
        protected void build(JsonSkeleton result, SkinnedMeshRenderer[] meshRenders)
        {
            var commonRoot = findSkinMeshCommonRoot(meshRenders);

            if (!commonRoot)
            {
                throw new System.ArgumentException("Coudl not find common root for skin mesh renderers");
            }

            var finalIds = gatherIds(commonRoot);            //gatherFilteredIds(prefabRoot.transform, commonRoot);

            Debug.LogFormat("Skinned mesh renderer skeleton:");
            printSkeleton(finalIds);

            result.clear();
            result.assignFrom(commonRoot, finalIds);
            result.name = findSkeletonName(commonRoot);
        }
Esempio n. 8
0
        protected void build(JsonSkeleton result, GameObject prefabRoot)
        {
            checkPrefabRoot(prefabRoot);

            var transformIds = gatherIds(prefabRoot.transform);

            Debug.LogFormat("Full skeleton:");
            printSkeleton(transformIds);

            var skinRenderers = prefabRoot.GetComponentsInChildren <SkinnedMeshRenderer>(true);
            var commonRoot    = findSkinMeshCommonRoot(skinRenderers, prefabRoot);
            var finalIds      = gatherFilteredIds(prefabRoot.transform, commonRoot);

            Debug.LogFormat("Short skeleton:");
            printSkeleton(finalIds);

            result.clear();
            result.assignFrom(commonRoot, finalIds);
            result.name = findSkeletonName(commonRoot);
        }