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(
        }
Esempio n. 2
0
        public JsonSkinRendererData(SkinnedMeshRenderer rend, GameObjectMapper objMap, ResourceMapper resMap)
        {
            if (!rend)
            {
                throw new System.ArgumentNullException("rend");
            }
            quality = rend.quality.ToString();
            skinnedMotionVectors = rend.skinnedMotionVectors;
            updateWhenOffscreen  = rend.updateWhenOffscreen;

            boneNames.Clear();
            boneIds.Clear();
            foreach (var cur in rend.bones)
            {
                boneNames.Add(cur.name);
                boneTransforms.Add(cur.localToWorldMatrix);
                boneIds.Add(objMap.getId(cur.gameObject));
            }

            var sharedMesh = rend.sharedMesh;

            meshId = resMap.getOrRegMeshId(rend, null);            //resMap.getMeshId(sharedMesh);

            materials.Clear();
            var sharedMats = rend.sharedMaterials;

            foreach (var curMat in sharedMats)
            {
                materials.Add(resMap.getMaterialId(curMat));
            }
        }
        public GameObjectMapper getPrefabObjectMapper(GameObject rootPrefab)
        {
            GameObjectMapper result = null;

            if (prefabObjects.TryGetValue(rootPrefab, out result))
            {
                return(result);
            }
            return(null);
        }
        void onNewRootPrefab(GameObject rootPrefab)
        {
            var newMapper = new GameObjectMapper();

            newMapper.gatherObjectIds(rootPrefab);
            foreach (var curObj in newMapper.objectList)
            {
                foreach (var meshFilter in curObj.GetComponents <MeshFilter>())
                {
                    getOrRegMeshId(meshFilter);
                }
                foreach (var meshRend in curObj.GetComponents <SkinnedMeshRenderer>())
                {
                    getOrRegMeshId(meshRend, null);
                }
            }
            prefabObjects.Add(rootPrefab, newMapper);
        }
Esempio n. 5
0
        public static JsonScene fromObjects(GameObject[] args, ResourceMapper resMap, bool showGui)
        {
            try{
                var result = new JsonScene();

                var objMap = new GameObjectMapper();
                foreach (var curObj in args)
                {
                    objMap.gatherObjectIds(curObj);
                }

                foreach (var curObj in objMap.objectList)
                {
                    resMap.gatherPrefabData(curObj);
                }

                for (int i = 0; i < objMap.objectList.Count; i++)
                {
                    /*TODO: The constructor CAN add more data, but most of it would've been added prior to this point.
                     * Contempalting whether to enforce it strictly or not.*/
                    if (showGui)
                    {
                        ExportUtility.showProgressBar("Collecting scene data",
                                                      string.Format("Adding scene object {0}/{1}", i, objMap.numObjects), i, objMap.objectList.Count);
                    }

                    var newObj = new JsonGameObject(objMap.objectList[i], objMap, resMap);
                    result.objects.Add(newObj);
                }
                return(result);
            }
            finally{
                if (showGui)
                {
                    ExportUtility.hideProgressBar();
                }
            }
        }
Esempio n. 6
0
        public JsonGameObject(GameObject obj, GameObjectMapper objMap, ResourceMapper resMap)
        {
            name          = obj.name;
            scenePath     = obj.getScenePath();
            instanceId    = obj.GetInstanceID();
            id            = objMap.getId(obj);
            localPosition = obj.transform.localPosition;
            localRotation = obj.transform.localRotation;
            localScale    = obj.transform.localScale;
            worldMatrix   = obj.transform.localToWorldMatrix;
            localMatrix   = worldMatrix;
            if (obj.transform.parent)
            {
                localMatrix = obj.transform.parent.worldToLocalMatrix * worldMatrix;
            }

            isStatic = obj.isStatic;
            var flags = GameObjectUtility.GetStaticEditorFlags(obj);

            lightMapStatic        = (flags & StaticEditorFlags.LightmapStatic) != 0;
            occluderStatic        = (flags & StaticEditorFlags.OccluderStatic) != 0;
            occludeeStatic        = (flags & StaticEditorFlags.OccludeeStatic) != 0;
            navigationStatic      = (flags & StaticEditorFlags.NavigationStatic) != 0;
            reflectionProbeStatic = (flags & StaticEditorFlags.ReflectionProbeStatic) != 0;

            activeSelf        = obj.activeSelf;
            activeInHierarchy = obj.activeInHierarchy;

            //var prefType = PrefabUtility.GetPrefabType(obj);
            //prefabType = prefType.ToString();
            prefabRootId   = resMap.getRootPrefabId(obj, true);
            prefabObjectId = resMap.getPrefabObjectId(obj, true);
            prefabInstance = Utility.isPrefabInstance(obj) || Utility.isPrefabModelInstance(obj);
            //prefabInstance = (prefType == PrefabType.PrefabInstance) || (prefType == PrefabType.ModelPrefabInstance);

            renderer         = JsonRendererData.makeRendererArray(obj.GetComponent <Renderer>(), resMap);
            light            = JsonLight.makeLightArray(obj.GetComponent <Light>());
            reflectionProbes =
                ExportUtility.convertComponents <ReflectionProbe, JsonReflectionProbe>(obj,
                                                                                       (c) => new JsonReflectionProbe(c, resMap)
                                                                                       );
            terrains =
                ExportUtility.convertComponents <Terrain, JsonTerrain>(obj,
                                                                       (c) => new JsonTerrain(c, resMap)
                                                                       );

            skinRenderers =
                ExportUtility.convertComponentsList <SkinnedMeshRenderer, JsonSkinRendererData>(obj,
                                                                                                (c) => new JsonSkinRendererData(c, objMap, resMap)
                                                                                                );

            int colliderIndex = 0;

            colliders = ExportUtility.convertComponentsList <Collider, JsonCollider>(
                obj, (arg) => new JsonCollider(arg, colliderIndex++, resMap)
                ).Where(c => c.isSupportedType()).ToList();

            for (int i = colliders.Count - 1; i >= 0; i--)
            {
                var curCollider = colliders[i];
                if ((curCollider == null) || !curCollider.isSupportedType())
                {
                    colliders.RemoveAt(i);
                }
            }

            rigidbodies = ExportUtility.convertComponentsList <Rigidbody, JsonRigidbody>(
                obj, (arg) => new JsonRigidbody(arg)
                );

            joints = ExportUtility.convertComponentsList <Joint, JsonPhysicsJoint>(
                obj, (arg) => new JsonPhysicsJoint(arg)
                );

            /*
             * if (rigidbodies.Count > 1){
             *      //Logger.log
             * }
             */

            ///..... I think those can be replaced with linq queries (-_-)

            /*
             * animators = obj.GetComponents<Animator>().Where((arg) => arg)
             *      .Select((Animator arg) => new JsonAnimator(arg, resMap))
             *      .ToList();*/

            animators =
                ExportUtility.convertComponentsList <Animator, JsonAnimator>(obj,
                                                                             (c) => new JsonAnimator(c, resMap));

            var meshFilter = obj.GetComponent <MeshFilter>();

            if (meshFilter)
            {
                mesh = resMap.getOrRegMeshId(meshFilter);
            }

            foreach (Transform curChild in obj.transform)
            {
                var childId = objMap.getId(curChild.gameObject);

                /* ????
                 * if (childId < 0){
                 *      //throw new System.ArgumentException("Could not find child id
                 * }
                 */
                if (!childId.isValid)
                {
                }
                //var childId = objMap.getId(curChild.gameObject);
                children.Add(childId);
                childNames.Add(curChild.name);
            }
            if (obj.transform.parent)
            {
                parentName = obj.transform.parent.name;
                parent     = objMap.findId(obj.transform.parent.gameObject);
            }
        }