public static (string[], string) GetDefaultTexturesAndActive(Imported model, string defFromVisibleMesh) { string[] textures = new string[model.materialMappings.Length]; SKAnimatorToolsProxy.IncrementEnd(textures.Length); for (int index = 0; index < model.materialMappings.Length; index++) { MaterialMapping mapping = model.materialMappings[index]; ConfigReference texRef = (ConfigReference)mapping.material.getArguments().getOrDefault("Texture", null); if (texRef != null) { string file = (string)texRef.getArguments().getOrDefault("File", null); if (file != null) { textures[index] = file; if (mapping.texture == defFromVisibleMesh) { defFromVisibleMesh = new FileInfo(file).Name; } } } SKAnimatorToolsProxy.IncrementProgress(); } return(textures, defFromVisibleMesh); }
private void Start() { if (fallbackLevelMaterial == null) { Debug.LogError("Fallback Level Material CAN NOT BE NULL!"); return; } foreach (Transform child in transform) { GameObject go = child.gameObject; ProBuilderMesh mainMesh = go.GetComponent <ProBuilderMesh>(); ArrayPacker[] faces = new ArrayPacker[mainMesh.faces.Count]; for (int i = 0; i < faces.Length; i++) { int[] faceVerts = new int[mainMesh.faces[i].indexes.Count]; mainMesh.faces[i].indexes.CopyTo(faceVerts, 0); faces[i] = new ArrayPacker(faceVerts); } Vector3[] vertices = new Vector3[mainMesh.positions.Count]; for (int i = 0; i < mainMesh.positions.Count; i++) { vertices[i] = mainMesh.positions[i]; } ArrayPacker[] sharedVertices = new ArrayPacker[mainMesh.sharedVertices.Count]; for (int i = 0; i < mainMesh.sharedVertices.Count; i++) { int[] sharedVertex = new int[mainMesh.sharedVertices[i].Count]; mainMesh.sharedVertices[i].CopyTo(sharedVertex, 0); sharedVertices[i] = new ArrayPacker(sharedVertex); } LevelPiece piece = new LevelPiece(go.transform.position, go.transform.rotation, vertices, faces, sharedVertices); Renderer renderer = go.GetComponent <Renderer>(); MaterialMapping mapping = MaterialMapping.GetMaterialMappingFromMaterial(levelMaterials, renderer.sharedMaterial); if (mapping != null) { piece.materialName = mapping.materialName; } else { piece.materialName = Constants.ERROR_NO_MATERIAL; } levelPieces.Add(piece); } // Was for testing to see duplicated data if (isTesting) { StartCoroutine(spawnBack()); } }
/* * Method was made for testing the data that was stored * in each individual level piece (gameObject) */ IEnumerator spawnBack() { yield return(new WaitForSeconds(0.1f)); GameObject level = new GameObject("[LOADED LEVEL]"); foreach (LevelPiece data in levelPieces) { List <Vertex> vertices = new List <Vertex>(); foreach (Vector3 position in data.vertices) { Vertex newPoint = new Vertex(); newPoint.position = position; vertices.Add(newPoint); } List <Face> faces = new List <Face>(); foreach (ArrayPacker face in data.faces) { faces.Add(new Face(face.array)); } List <SharedVertex> sharedVertices = new List <SharedVertex>(); foreach (ArrayPacker shared in data.sharedVertices) { sharedVertices.Add(new SharedVertex(shared.array)); } ProBuilderMesh pbMesh = ProBuilderMesh.Create(vertices, faces, sharedVertices); GameObject generatedObject = pbMesh.gameObject; generatedObject.transform.position = offset + data.position; generatedObject.transform.rotation = data.rotation; MaterialMapping mapping = MaterialMapping.GetMaterialMappingFromName(levelMaterials, data.materialName); if (mapping != null) { generatedObject.GetComponent <Renderer>().sharedMaterial = mapping.material; } else { generatedObject.GetComponent <Renderer>().sharedMaterial = fallbackLevelMaterial; } generatedObject.AddComponent <MeshCollider>(); generatedObject.transform.parent = level.transform; } }
private void PopulateFromMapping( H2vMap map, Material <BitmapTag> mat, ShaderTag.ShaderTemplateArguments args, MaterialMapping mapping) { mat.NormalMap = args.GetBitmap(map, mapping.NormalMapIndex); mat.NormalMapScale = args.GetInput(mapping.NormalScaleIndex); mat.DiffuseMap = args.GetBitmap(map, mapping.DiffuseMapIndex); if (mapping.DiffuseColor.Length == 4) { mat.DiffuseColor = new Vector4(mapping.DiffuseColor[0], mapping.DiffuseColor[1], mapping.DiffuseColor[2], mapping.DiffuseColor[3]); } else if (mapping.DiffuseColor.Length == 1) { mat.DiffuseColor = new Vector4(mapping.DiffuseColor[0]); } mat.DetailMap1 = args.GetBitmap(map, mapping.Detail1MapIndex); mat.Detail1Scale = args.GetInput(mapping.Detail1ScaleIndex); mat.DetailMap2 = args.GetBitmap(map, mapping.Detail2MapIndex); mat.Detail2Scale = args.GetInput(mapping.Detail2ScaleIndex); mat.EmissiveMap = args.GetBitmap(map, mapping.EmissiveMapIndex); mat.EmissiveArguments = args.GetInput(mapping.EmissiveArgumentsIndex); mat.EmissiveType = mapping.EmissiveType; mat.AlphaMap = args.GetBitmap(map, mapping.AlphaMapIndex); mat.AlphaFromRed = mapping.AlphaFromRed; mat.ColorChangeMask = args.GetBitmap(map, mapping.ColorChangeMaskMapIndex); mat.SpecularMap = args.GetBitmap(map, mapping.SpecularMapIndex); }
/// <summary> /// Returns the currently active textures for each of the <see cref="MaterialMapping"/>s within this <see cref="ModelConfig"/>.<para/> /// This will only pull the textures actively in use by the model. Any other variants will not be acquired. /// </summary> /// <param name="model"></param> /// <returns></returns> public static string[] GetDefaultTextures(Imported model) { string[] textures = new string[model.materialMappings.Length]; SKAnimatorToolsProxy.IncrementEnd(textures.Length); for (int index = 0; index < model.materialMappings.Length; index++) { MaterialMapping mapping = model.materialMappings[index]; ConfigReference texRef = (ConfigReference)mapping.material.getArguments().getOrDefault("Texture", null); if (texRef != null) { string file = (string)texRef.getArguments().getOrDefault("File", null); if (file != null) { textures[index] = file; } } SKAnimatorToolsProxy.IncrementProgress(); } /* * for (int index = 0; index < model.materialMappings.Length; index++) { * MaterialMapping mapping = model.materialMappings[index]; * MaterialConfig material = mapping.material.ResolveAuto<MaterialConfig>(); * if (material != null) { * while (material.implementation is MaterialConfig.Derived derivedMtl) { * material = derivedMtl.material.ResolveAuto<MaterialConfig>(); * } * * if (material.implementation is MaterialConfig.Original originalMtl) { * foreach (TechniqueConfig technique in originalMtl.techniques) { * TechniqueConfig.Enqueuer enqueuer = technique.enqueuer; * if (enqueuer is TechniqueConfig.NormalEnqueuer normalEnq) { * foreach (PassConfig pass in normalEnq.passes) { * // Just find the first pass with a texture. It's not possible to have multiple textures right now in gltf * // that is, on one model * if (pass.textureState != null) { * TextureStateConfig texState = pass.textureState; * if (texState.units.Length > 0) { * TextureConfig texture = texState.units[0].texture.ResolveAuto<TextureConfig>(); * while (texture.implementation is TextureConfig.Derived derivedTexture) { * texture = derivedTexture.texture.ResolveAuto<TextureConfig>(); * } * * if (texture.implementation is TextureConfig.Original2D tex2d) { * TextureConfig.Original2D.Contents contents = tex2d.contents; * if (contents is TextureConfig.Original2D.ImageFile imageFile) { * textures[index] = imageFile.file; * } else { * // Blank. * textures[index] = null; * } * } else { * XanLogger.WriteLine("Unsupported texture type " + texture.GetType().Name); * } * } * } * } * } * } * } * } * * SKAnimatorToolsProxy.IncrementProgress(); * } */ return(textures); }