/*
         * 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
                                      ));
        }
Ejemplo n.º 2
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);
        }
        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) => ;
        }