Example #1
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 JsonRendererData(Renderer r, ResourceMapper resMap)
 {
     receiveShadows      = r.receiveShadows;
     shadowCastingMode   = r.shadowCastingMode.ToString();
     lightmapIndex       = r.lightmapIndex;
     lightmapScaleOffset = r.lightmapScaleOffset;
     foreach (var cur in r.sharedMaterials)
     {
         materials.Add(resMap.getMaterialId(cur));
     }
 }
Example #3
0
 public static void registerLinkedData(Terrain obj, ResourceMapper resMap)
 {
     if (!obj)
     {
         return;
     }
     if (obj.materialType == Terrain.MaterialType.Custom)
     {
         resMap.getMaterialId(obj.materialTemplate);
     }
     resMap.getTerrainId(obj.terrainData);
 }
Example #4
0
        public JsonTerrain(Terrain srcObj, ResourceMapper resMap)
        {
            if (!srcObj)
            {
                throw new System.ArgumentNullException("srcObj");
            }

            castShadows          = srcObj.castShadows;
            detailObjectDensity  = srcObj.detailObjectDensity;
            detailObjectDistance = srcObj.detailObjectDistance;
            drawHeightmap        = srcObj.drawHeightmap;
            drawTreesAndFoliage  = srcObj.drawTreesAndFoliage;

            renderHeightmap = (srcObj.editorRenderFlags & TerrainRenderFlags.Heightmap) != 0;
            renderTrees     = (srcObj.editorRenderFlags & TerrainRenderFlags.Trees) != 0;
            renderDetails   = (srcObj.editorRenderFlags & TerrainRenderFlags.Details) != 0;

            heightmapPixelError = srcObj.heightmapPixelError;

            legacyShininess    = srcObj.legacyShininess;
            legacySpecular     = srcObj.legacySpecular;
            lightmapIndex      = srcObj.lightmapIndex;
            lightmapScaleOffet = srcObj.lightmapScaleOffset;

            materialType = srcObj.materialType.ToString();

            patchBoundsMultiplier       = srcObj.patchBoundsMultiplier;
            preserveTreePrototypeLayers = srcObj.preserveTreePrototypeLayers;
            realtimeLightmapIndex       = srcObj.realtimeLightmapIndex;
            realtimeLightmapScaleOffset = srcObj.realtimeLightmapScaleOffset;

            treeBillboardDistance = srcObj.treeBillboardDistance;
            treeCrossFadeLength   = srcObj.treeCrossFadeLength;

            treeDistance          = srcObj.treeDistance;
            treeLodBiasMultiplier = srcObj.treeLODBiasMultiplier;

            treeMaximumFullLODCount = srcObj.treeMaximumFullLODCount;

            //And once again I doubt whehter the approahc of making a temporary object is justified.
            materialTemplateIndex = ResId.invalid;
            if (srcObj.materialType == Terrain.MaterialType.Custom)
            {
                materialTemplateIndex = resMap.getMaterialId(srcObj.materialTemplate);                //-1;
            }
            //material keeps picking up splat texutre :-\
            terrainDataId = resMap.getTerrainId(srcObj.terrainData);
            //public int terrainDataId = -1;
        }
        bool addMaterialAsset(AssetInfo asset, bool showGui, Logger logger)
        {
            Logger.makeValid(ref logger);
            AssetDatabase.LoadAllAssetsAtPath(asset.path);
            var mainAsset = AssetDatabase.LoadMainAssetAtPath(asset.path);
            var mat       = mainAsset as Material;

            if (!mainAsset || !mat)
            {
                logger.logErrorFormat("Could not load material at path {0}({1})", asset.path, asset.guid);
                return(true);
            }
            var id = resourceMapper.getMaterialId(mat);

            if (!ExportUtility.isValidId(id))
            {
                logger.logWarningFormat("Could not create id for material {0}({1})", asset.path, asset.guid);
            }
            return(true);
        }
Example #6
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));
                }
            }
        }
Example #7
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();
		}