public static void registerLinkedData(Material mat, ResourceMapper resMap)
 {
     if (!mat)
     {
         return;
     }
     registerLinkedTex(mat, TexParamNames.main, resMap);
     registerLinkedTex(mat, TexParamNames.specular, resMap);
     registerLinkedTex(mat, TexParamNames.metallic, resMap);
     registerLinkedTex(mat, TexParamNames.normal, resMap);
     registerLinkedTex(mat, TexParamNames.occlusion, resMap);
     registerLinkedTex(mat, TexParamNames.parallax, resMap);
     registerLinkedTex(mat, TexParamNames.emission, resMap);
     registerLinkedTex(mat, TexParamNames.detailMask, resMap);
     registerLinkedTex(mat, TexParamNames.detailAlbedo, resMap);
     registerLinkedTex(mat, TexParamNames.detailNormal, resMap);
 }
        public JsonTexture(Texture tex, ResourceMapper resMap)
        {
            name = tex.name;
            id   = resMap.findTextureId(tex);          //exp.textures.findId(tex);
            var assetPath = AssetDatabase.GetAssetPath(tex);

            resMap.registerAssetPath(assetPath);
            path       = assetPath;
            filterMode = tex.filterMode.ToString();
            width      = tex.width;
            height     = tex.height;
            wrapMode   = tex.wrapMode.ToString();
            var tex2D      = tex as Texture2D;
            var rendTarget = tex as RenderTexture;

            isTex2D        = tex2D != null;
            isRenderTarget = rendTarget != null;
            var importer    = AssetImporter.GetAtPath(assetPath);
            var texImporter = importer as TextureImporter;            //(TextureImporter)importer;

            if (isTex2D)
            {
                alphaTransparency = tex2D.alphaIsTransparency;
                format            = tex2D.format.ToString();
            }
            if (isRenderTarget)
            {
                anisoLevel = rendTarget.anisoLevel;
            }
            if (texImporter)
            {
                importDataFound = true;
                sRGB            = texImporter.sRGBTexture;
                textureType     = texImporter.textureType.ToString();
                normalMapFlag   = (texImporter.textureType == TextureImporterType.NormalMap);
            }

            texParams       = new JsonTextureParameters(tex);
            texImportParams = new JsonTextureImportParameters(texImporter);

            textureRef = tex;
        }
        public JsonCubemap(Cubemap cubemap_, ResourceMapper resMap)
        {
            cubemap = cubemap_;
            if (!cubemap)
            {
                return;
            }
            id        = resMap.findCubemapId(cubemap);
            assetPath = AssetDatabase.GetAssetPath(cubemap);
            name      = cubemap.name;

            var importer    = AssetImporter.GetAtPath(assetPath);
            var texImporter = importer as TextureImporter;

            texParams       = new JsonTextureParameters(cubemap);
            texImportParams = new JsonTextureImportParameters(texImporter);

            needConversion = true;

            /*
             * if (TextureUtility.isSupportedTexExtension(assetPath))
             *      needConversion = true;
             * if (texImportParams.initialized && texImportParams.importer){
             *      if (texImportParams.importer.generateCubemap != TextureImporterGenerateCubemap.FullCubemap){
             *              needConversion = true;
             *      }
             *      //huh.... I don't really have a way to get original texture dimensiosn, it looks like it. Oh well?
             * }
             */

            format = cubemap.format.ToString();
            isHdr  = TextureUtility.isHdrFormat(cubemap.format);

            exportPath = assetPath;
            rawPath    = "";
            if (needConversion)
            {
                exportPath = System.IO.Path.ChangeExtension(assetPath, ".png");
                rawPath    = System.IO.Path.ChangeExtension(assetPath, ".raw");
            }
        }
        public JsonAnimationClip(AnimationClip clip_, Animator animator_, ResId id_, ResourceMapper resMap, AnimationSampler animSampler = null)
        {
            clip     = clip_;
            id       = id_;
            animator = animator_;
            if (!clip)
            {
                throw new System.ArgumentNullException("clip_");
            }
            if (!animator)
            {
                throw new System.ArgumentNullException("animator_");
            }
            if (resMap == null)
            {
                throw new System.ArgumentNullException("resMap");
            }

            name = clip.name;
            sampleMatrixCurves(resMap, animSampler);
        }
Exemplo n.º 5
0
        public MeshIdData(GameObject srcObj, ResourceMapper resMap)
        {
            if (!srcObj)
            {
                return;
            }
            var filter = srcObj.GetComponent <MeshFilter>();

            if (filter && filter.sharedMesh)
            {
                meshId = resMap.getMeshId(filter.sharedMesh, MeshUsageFlags.None);
            }
            var renderer = srcObj.GetComponent <Renderer>();

            if (renderer)
            {
                foreach (var cur in renderer.sharedMaterials)
                {
                    meshMaterials.Add(resMap.getMaterialId(cur));
                }
            }
        }
Exemplo n.º 6
0
        public JsonPrefabData(GameObject prefabObject, ResourceMapper resMap)
        {
            id = resMap.getRootPrefabId(prefabObject, true);

            path = AssetDatabase.GetAssetPath(prefabObject);
            guid = AssetDatabase.AssetPathToGUID(path);
            //name = System.IO.Path.GetFileName(path);
            name = prefabObject.name;            //looks like name of prefab mirrors that of a file, sans extension
            //prefabType = PrefabUtility.GetPrefabType(prefabObject).ToString();
            prefabAssetType      = PrefabUtility.GetPrefabAssetType(prefabObject).ToString();
            prefabInstanceStatus = PrefabUtility.GetPrefabInstanceStatus(prefabObject).ToString();

            var mapper = resMap.getPrefabObjectMapper(prefabObject);

            for (int i = 0; i < mapper.numObjects; i++)
            {
                ///Well, this is certainly not the best way to go about it...
                var src = mapper.getObjectByIndex(i);
                var dst = new JsonGameObject(src, mapper, resMap);
                objects.Add(dst);
            }
        }
Exemplo n.º 7
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();
                }
            }
        }
Exemplo n.º 8
0
        public JsonAnimatorController(UnityEditor.Animations.AnimatorController controller_, Animator animator, ResId id_, ResourceMapper resMap)
        {
            controller = controller_;
            if (!controller)
            {
                throw new System.ArgumentNullException("controller_");
            }
            if (!animator)
            {
                throw new System.ArgumentNullException("animator");
            }
            id   = id_;
            name = controller.name;
            path = AssetDatabase.GetAssetPath(controller);

            parameters   = controller.parameters.Select((arg) => new JsonAnimatorControllerParameter(arg)).ToList();
            animationIds = controller.animationClips.Select((arg) => resMap.getAnimationClipId(arg, animator)).ToList();
            //animations = controller.animationClips.Select((arg, idx) => new JsonAnimationClip(arg, idx)).ToList();
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
		public JsonMesh(MeshStorageKey meshKey, ResId id_, ResourceMapper resMap){
			id = id_;
			usageFlags = meshKey.usageFlags;
			convexCollider = meshKey.usageFlags.HasFlag(MeshUsageFlags.ConvexCollider);
			triangleCollider = meshKey.usageFlags.HasFlag(MeshUsageFlags.TriangleCollider);

			var mesh = meshKey.mesh;
            if (mesh == null)
            {
                Debug.LogError("Mesh is null, name!");
                return;
            }
			name = mesh.name;
			var filePath = AssetDatabase.GetAssetPath(mesh);
			resMap.registerAssetPath(filePath);
			path = filePath;
			uniqueName = resMap.createUniqueAssetName(filePath, name, meshKey.getMeshAssetSuffix());

			var foundMaterials = resMap.findMeshMaterials(mesh);
			if (foundMaterials != null){
				foreach(var cur in foundMaterials){
					materials.Add(resMap.getMaterialId(cur));
				}
			}

			#if !UNITY_EDITOR
			readable = mesh.isReadable;
			if (!readable){
				Debug.LogErrorFormat(string.Format("Mesh {0} is not marked as readable. Cannot proceed", name);
				return;
			}
			#endif
			
			vertexCount = mesh.vertexCount;
			if (vertexCount <= 0)
				return;

			colors = mesh.colors32.toByteArray();
			verts = mesh.vertices.toFloatArray();
			normals = mesh.normals.toFloatArray();
			
			tangents = mesh.tangents.toFloatArray();
			
			uv0 = mesh.uv.toFloatArray();
			uv1 = mesh.uv2.toFloatArray();
			uv2 = mesh.uv3.toFloatArray();
			uv3 = mesh.uv4.toFloatArray();			
			uv4 = mesh.uv5.toFloatArray();			
			uv5 = mesh.uv6.toFloatArray();			
			uv6 = mesh.uv7.toFloatArray();			
			uv7 = mesh.uv8.toFloatArray();			

			subMeshCount = mesh.subMeshCount;
			for(int i = 0; i < subMeshCount; i++){
				var subMesh = new SubMesh();
				subMesh.triangles = Utility.copyArray(mesh.GetTriangles(i));
				subMeshes.Add(subMesh);
			}
			
			boneWeights.Clear();
			boneIndexes.Clear();
			defaultSkeletonId = resMap.skelRegistry.getDefaultSkeletonId(meshKey);
			defaultBoneNames = resMap.skelRegistry.getDefaultBoneNames(meshKey);
			
			defaultMeshNodeName = resMap.skelRegistry.getDefaultMeshNodeName(meshKey);
			defaultMeshNodePath = resMap.skelRegistry.getDefaultMeshNodePath(meshKey);
			defaultMeshNodeMatrix = resMap.skelRegistry.getDefaultMeshNodeMatrix(meshKey);
			
			var srcWeights = mesh.boneWeights;
			if ((srcWeights != null) && (srcWeights.Length > 0)){
				foreach(var cur in srcWeights){
					boneIndexes.Add(cur.boneIndex0);
					boneIndexes.Add(cur.boneIndex1);
					boneIndexes.Add(cur.boneIndex2);
					boneIndexes.Add(cur.boneIndex3);
					
					boneWeights.Add(cur.weight0);
					boneWeights.Add(cur.weight1);
					boneWeights.Add(cur.weight2);
					boneWeights.Add(cur.weight3);
				}
			}
			
			blendShapeCount = mesh.blendShapeCount;
			blendShapes.Clear();
			for(int i = 0; i < blendShapeCount; i++){
				blendShapes.Add(new JsonBlendShape(mesh, i));
			}
			
			bindPoses = mesh.bindposes.ToList();
		}
Exemplo n.º 11
0
 public void clear()
 {
     config = new JsonProjectConfig();
     scenes.Clear();
     resourceMapper = new ResourceMapper();
 }
        void sampleMatrixCurves(ResourceMapper resMap, AnimationSampler providedSampler = null)
        {
            var skelId = resMap.skelRegistry.registerSkeleton(animator.transform, true);

            if (!ExportUtility.isValidId(skelId))
            {
                throw new System.ArgumentException(
                          string.Format("Skeleton not found for clip \"{0}\" and animator \"{1}\"",
                                        clip, animator));
            }
            var skeleton = resMap.skelRegistry.getSkeletonById(skelId);

            var prefabAnim = Utility.getSrcPrefabAssetObject(animator, false);

            if (providedSampler != null)
            {
                var sampled = providedSampler.sampleClip(clip);
                matrixCurves = sampled;                //.matrixCurves;
                //sampledFloatCurves = sampled.floatCurves;
            }
            else
            {
                using (var sampler = new AnimationSampler(prefabAnim, skeleton)){
                    var sampled = sampler.sampleClip(clip);
                    matrixCurves = sampled;                    //.matrixCurves;
                    //sampledFloatCurves = sampled.floatCurves;
                }
            }

            matrixCurves.forEach((obj) => obj.simpleCompress());

                        #if false
            //Black magic: on!
            //Spawning a duplicate

            var spawnedAnimator = GameObject.Instantiate(prefabAnim);
            if (!spawnedAnimator)
            {
                throw new System.Exception("Instantiating of original object failed while sampling animation");
            }

            var transformRoot = spawnedAnimator.transform;

            var foundTransforms = Utility.findNamedTransforms(
                skeleton.bones.Select((arg) => arg.name).ToList(),
                transformRoot);
            //This needs to be moved elsewhere.

            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);
            var animControllerAssetPath = AssetDatabase.GenerateUniqueAssetPath(animControllerBaseAssetPath);
            Debug.LogFormat("generated path: {0}", animControllerAssetPath);
            var newController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(
                animControllerAssetPath);

            var stateMachine = newController.layers[0].stateMachine;
            var stateName    = "clip";
            var state        = newController.layers[0].stateMachine.AddState(stateName);
            stateMachine.defaultState = state;

            spawnedAnimator.runtimeAnimatorController = newController;

            var firstTime = 0.0f;
            var lastTime  = clip.length;
            var timeStep  = 1.0f / clip.frameRate;

            spawnedAnimator.Play(stateName, 0, 0.0f);

            for (int transformIndex = 0; transformIndex < foundTransforms.Count; transformIndex++)
            {
                var curTransform = foundTransforms[transformIndex];
                var newCurve     = new JsonAnimationMatrixCurve();
                newCurve.objectName = skeleton.bones[transformIndex].name;
                matrixCurves.Add(newCurve);
            }

            for (float t = firstTime; t <= lastTime; t += timeStep)
            {
                clip.SampleAnimation(spawnedAnimator.gameObject, t);
                for (int transformIndex = 0; transformIndex < foundTransforms.Count; transformIndex++)
                {
                    var curTransform = foundTransforms[transformIndex];
                    if (!curTransform)
                    {
                        continue;
                    }
                    matrixCurves[transformIndex].addKey(t, curTransform, spawnedAnimator.transform);
                }
                ///sampleSingleFramePoints(spawnedAnimator, boneIds, t/lastTime);
            }

            foreach (var cur in matrixCurves)
            {
                cur.simpleCompress();
            }

            if (spawnedAnimator)
            {
                GameObject.DestroyImmediate(spawnedAnimator.gameObject);
            }
            if (newController)
            {
                AssetDatabase.DeleteAsset(animControllerAssetPath);
            }
                        #endif
        }
 public JsonSplatPrototype(SplatPrototype data_, ResourceMapper resMap)
 {
     data        = data_;
     textureId   = resMap.getTextureId(data.texture);
     normalMapId = resMap.getTextureId(data.normalMap);
 }
Exemplo n.º 14
0
        public JsonMaterial(Material mat, ResourceMapper resMap)
        {
            name = mat.name;
            //TODO: Further investigation shows that this is likely going to return -1 for all new materials.
            id          = resMap.findMaterialId(mat);   //exp.materials.findId(mat);
            renderQueue = mat.renderQueue;
            var path = AssetDatabase.GetAssetPath(mat);

            this.path = path;
            shader    = mat.shader.name;

            supportedShader = isSupportedShaderName(shader);

            mainTexture       = resMap.getTextureId(mat.mainTexture);
            mainTextureOffset = mat.mainTextureOffset;
            mainTextureScale  = mat.mainTextureScale;
            color             = getColor(mat, ParamNames.mainColor, Color.white);    //mat.color;

            useNormalMap        = mat.IsKeywordEnabled(Keywords.normalMap);          //"_NORMALMAP");
            useAlphaTest        = mat.IsKeywordEnabled(Keywords.alphaTestOn);        //"_ALPHATEST_ON");
            useAlphaBlend       = mat.IsKeywordEnabled(Keywords.alphaBlendOn);       //"_ALPHABLEND_ON");
            useAlphaPremultiply = mat.IsKeywordEnabled(Keywords.alphaPremultiplyOn); //"_ALPHAPREMULTIPLY_ON");
            useEmission         = mat.IsKeywordEnabled(Keywords.emission);           //"_EMISSION");
            useParallax         = mat.IsKeywordEnabled(Keywords.parallaxMap);        //"_PARALLAXMAP");
            useDetailMap        = mat.IsKeywordEnabled(Keywords.detailMulX2);        //"_DETAIL_MULX2");
            useMetallic         = mat.IsKeywordEnabled(Keywords.metallicGlossMap);   //"_METALLICGLOSSMAP");
            useSpecular         = mat.IsKeywordEnabled(Keywords.specGlossMap);       //"_SPECCGLOSSMAP");

            albedoTex          = getTexId(mat, TexParamNames.main, resMap);
            specularTex        = getTexId(mat, TexParamNames.specular, resMap);
            metallicTex        = getTexId(mat, TexParamNames.metallic, resMap);
            normalMapTex       = getTexId(mat, TexParamNames.normal, resMap);
            occlusionTex       = getTexId(mat, TexParamNames.occlusion, resMap);
            parallaxTex        = getTexId(mat, TexParamNames.parallax, resMap);
            emissionTex        = getTexId(mat, TexParamNames.emission, resMap);
            detailMaskTex      = getTexId(mat, TexParamNames.detailMask, resMap);
            detailAlbedoTex    = getTexId(mat, TexParamNames.detailAlbedo, resMap);
            detailNormalMapTex = getTexId(mat, TexParamNames.detailNormal, resMap);

            detailAlbedoScale  = getTextureScale(mat, TexParamNames.detailAlbedo);           //mat.GetTextureScale(TexParamNames.detailAlbedo);
            detailAlbedoOffset = getTextureOffset(mat, TexParamNames.detailAlbedo);          //mat.GetTextureOffset(TexParamNames.detailAlbedo);

            detailNormalMapScale = getFloat(mat, ParamNames.detailNormalMapScale, 1.0f);

            alphaCutoff       = getFloat(mat, ParamNames.cutoff, 1.0f);
            smoothness        = getFloat(mat, ParamNames.glossiness, 0.5f);
            smoothnessScale   = getFloat(mat, ParamNames.glossinessScale, 1.0f);
            specularColor     = getColor(mat, ParamNames.specularColor, Color.white);
            metallic          = getFloat(mat, ParamNames.metallic, 0.5f);
            bumpScale         = getFloat(mat, ParamNames.bumpScale, 1.0f);
            parallaxScale     = getFloat(mat, ParamNames.parallax, 1.0f);
            occlusionStrength = getFloat(mat, ParamNames.occlusionStrength, 1.0f);

            emissionColor  = getColor(mat, ParamNames.emissionColor, Color.black);
            detailMapScale = getFloat(mat, ParamNames.detailNormalMapScale, 1.0f);
            secondaryUv    = getFloat(mat, ParamNames.secondaryUv, 1.0f);

            blendMode = Mathf.RoundToInt(getFloat(mat, ParamNames.blendMode, 0.0f));

            smoothnessMapChannel = (int)getFloat(mat, ParamNames.smoothnessMapChannel, 0.0f);
            specularHighlights   = getFloat(mat, ParamNames.specularHighlights, 1.0f);
            glossyReflections    = getFloat(mat, ParamNames.glossyReflections, 1.0f);

            hasMetallic      = mat.HasProperty(ParamNames.metallic) && mat.HasProperty(TexParamNames.metallic);
            hasSpecular      = mat.HasProperty(TexParamNames.specular) && mat.HasProperty(ParamNames.specularColor);
            hasEmissionColor = mat.HasProperty(ParamNames.emissionColor) && (emissionColor.maxColorComponent > 0.01f);
            hasEmission      = hasEmissionColor || ExportUtility.isValidId(emissionTex);       //(emissionTex >= 0);
        }
Exemplo n.º 15
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));
            }
        }
Exemplo n.º 16
0
        public JsonTerrainData(TerrainData terrainData_, ResourceMapper resMap)
        {
            if (!terrainData_)
            {
                throw new System.ArgumentNullException("terrainData_");
            }

            terrainData = terrainData_;

            name       = terrainData.name;
            path       = AssetDatabase.GetAssetPath(terrainData);
            exportPath = string.Format("{0}/{1}", terrainAssetExportFolder, path);            //System.IO.Path.Combine(terrainAssetExportFolder, path);
            exportPath = System.IO.Path.ChangeExtension(exportPath, ".bin");

            heightMapRawPath = System.IO.Path.ChangeExtension(exportPath, ".height.raw");
            detailMapRawPaths.Clear();
            alphaMapRawPaths.Clear();

            for (int i = 0; i < terrainData.alphamapLayers; i++)
            {
                var rawExt = string.Format(".alpha{0}.raw", i);
                alphaMapRawPaths.Add(System.IO.Path.ChangeExtension(exportPath, rawExt));
            }

            bounds = new JsonBounds(terrainData.bounds);

            detailPrototypes.Clear();
            var srcDetailPrototypes = terrainData.detailPrototypes;

            foreach (var cur in srcDetailPrototypes)
            {
                detailPrototypes.Add(new JsonTerrainDetailPrototype(cur, resMap));
            }

            for (int i = 0; i < detailPrototypes.Count; i++)
            {
                var rawExt = string.Format(".detail{0}.raw", i);
                detailMapRawPaths.Add(System.IO.Path.ChangeExtension(exportPath, rawExt));
            }

            var srcTreePrototypes = terrainData.treePrototypes;

            treePrototypes.Clear();
            foreach (var cur in srcTreePrototypes)
            {
                treePrototypes.Add(new JsonTreePrototype(cur, resMap));
            }

            //writer.writeKeyVal("treeInstances", treeInstances);
            var srcTreeInstances = terrainData.treeInstances;

            treeInstances.Clear();
            foreach (var cur in srcTreeInstances)
            {
                treeInstances.Add(new JsonTreeInstance(cur));
            }

            var splats = terrainData.splatPrototypes;

            splatPrototypes.Clear();
            foreach (var cur in splats)
            {
                splatPrototypes.Add(new JsonSplatPrototype(cur, resMap));
            }


            //TODO: detail layer?
        }
Exemplo n.º 17
0
 public static JsonScene fromObject(GameObject arg, ResourceMapper resMap, bool showGui)
 {
     return(fromObjects(new GameObject[] { arg }, resMap, showGui));
 }