public JsonCharacter(Animator animator_, int id_, ResourceMapper resMap)
        {
            id = id_;
            if (!animator_)
            {
                throw new System.ArgumentNullException("animator_");
            }
            animator = animator_;
            if (resMap == null)
            {
                throw new System.ArgumentNullException("resMap");
            }

            name      = animator.name;
            assetPath = AssetDatabase.GetAssetPath(animator);

            //skeleton = new JsonSkeleton(animator.name, id, animator.transform, characterObjectMapper);
            var skeleton = JsonSkeletonBuilder.buildFromRootTransform(animator.transform);

            var objects = harvestAttachedObjects(animator);
            var characterObjectMapper = new GameObjectMapper();            //Hmm....

            attachedObjects = objects.Select((arg) => new JsonGameObject(arg, characterObjectMapper, resMap)).ToList();

            //Hmm. Because of retargeting, we will need to possibly create multiple copies of a single animator controller.

            //var JsonAnimatorController(
        }
Exemplo 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);
        }
Exemplo n.º 3
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);
        }
        /*
         * ResId getOrRegMeshId(MeshStorageKey meshKey, GameObject obj, Mesh mesh){
         *      if (!mesh){
         *              return ResId.invalid;
         *      }
         *      ResId result = meshes.getId(meshKey, true, null);
         *      if (meshMaterials.ContainsKey(mesh))
         *              return result;
         *
         *      var r = obj.GetComponent<Renderer>();
         *      if (r){
         *              meshMaterials[mesh] = new List<Material>(r.sharedMaterials);
         *      }
         *      return result;
         * }
         */

        public MeshStorageKey buildMeshKey(SkinnedMeshRenderer meshRend, bool includeSkeleton)
        {
            var mesh = meshRend.sharedMesh;

            /*
             * Subtle. FindPrefabRoot does not find the root of the original object, but rather a root of object currently being processed.
             * Meaning if you apply it to an instanced prefab, it'll find root of that that instanced prefab in the scene, and not the original asset
             */
            var prefabRoot = Utility.getSrcPrefabAssetObject(
                Utility.getPrefabInstanceRoot(meshRend.gameObject),
                //PrefabUtility.FindPrefabRoot(meshRend.gameObject),
                false
                );

            Transform skeletonRoot = null;

            if (includeSkeleton)
            {
                skeletonRoot = Utility.getSrcPrefabAssetObject(JsonSkeletonBuilder.findSkeletonRoot(meshRend), false);
            }
            return(new MeshStorageKey(mesh,
                                      MeshUsageFlags.None, //We're simply rendering this.
                                      prefabRoot, skeletonRoot
                                      ));
        }
        public void rebuildMesh()
        {
            if (!skinMeshRend)
            {
                return;
            }
            var resMap = new ResourceMapper();
            //jsonMesh = new JsonMesh(new Mesh)

            var prefabRoot        = ExportUtility.getLinkedRootPrefabAsset(skinMeshRend.gameObject);
            var assetSkeletonRoot = JsonSkeletonBuilder.findSkeletonRoot(skinMeshRend);
            var mesh = skinMeshRend.sharedMesh;

            jsonMesh = new JsonMesh(new MeshStorageKey(mesh, prefabRoot, assetSkeletonRoot), 0, resMap);

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

            origTransforms = skinMeshRend.bones.ToList();
            if (skeletonRoot)
            {
                debugTransforms = Utility.findNamedTransforms(boneNames, skeletonRoot);
            }
            else
            {
                debugTransforms = null;
            }
            //var foundTransforms = boneNames.Select((arg) => ;
        }
Exemplo n.º 6
0
        public static JsonSkeleton buildFromRootTransform(Transform prefabTransform)
        {
            var result  = new JsonSkeleton();
            var builder = new JsonSkeletonBuilder();

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

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

            builder.build(result, new SkinnedMeshRenderer[] { meshRend });
            return(result);
        }