private IEnumerator ShowAvatarByCode(string sCode) { // with known avatar code we can get TexturedMesh for head in order to show it further var avatarHeadRequest = avatarProvider.GetHeadMeshAsync(sCode, true); yield return(AwaitRoutine(avatarHeadRequest)); TexturedMesh headTexturedMesh = avatarHeadRequest.Result; TexturedMesh haircutTexturedMesh = null; // get identities of all haircuts available for the generated avatar var haircutsIdRequest = avatarProvider.GetHaircutsIdAsync(sCode); yield return(AwaitRoutine(haircutsIdRequest)); // randomly select a haircut var haircuts = haircutsIdRequest.Result; var haircutIdx = 0; if (haircuts != null && haircuts.Length > 0) { haircutIdx = UnityEngine.Random.Range(0, haircuts.Length); var haircut = haircuts[haircutIdx]; // load TexturedMesh for the chosen haircut var haircutRequest = avatarProvider.GetHaircutMeshAsync(sCode, haircut); yield return(AwaitRoutine(haircutRequest)); haircutTexturedMesh = haircutRequest.Result; } var avatarInfo = CreateHead(sCode, headTexturedMesh, haircutTexturedMesh); avatarInfo.code = sCode; avatarInfo.name = ReadAvatarNameByCode(sCode); avatarInfo.haircuts = haircuts; avatarInfo.selectedHairstyle = haircutIdx; avatarInfo.transform.position = Vector3.zero; avatarInfo.transform.localRotation = avatarInitialRotation; Selection.activeGameObject = avatarInfo.gameObject; SceneView sceneView = SceneView.lastActiveSceneView; if (sceneView == null) { Type GameViewType = System.Type.GetType("UnityEditor.GameView,UnityEditor"); sceneView = EditorWindow.GetWindow <SceneView>(new Type[] { GameViewType }); } if (sceneView != null) { Camera sceneCam = sceneView.camera; sceneView.pivot = Vector3.zero; sceneView.size = cameraOffset; sceneView.LookAt(Vector3.zero, Quaternion.identity); } Tools.current = Tool.Rotate; }
private IEnumerator DownloadAvatar(BodyAttachment bodyAttachment, string avatarCode, string haircutIdentity, string hairColor) { // download head var headRequest = avatarProvider.GetHeadMeshAsync(avatarCode, true); yield return(Await(headRequest)); TexturedMesh headTexturedMesh = headRequest.Result; // download haircut TexturedMesh haircutTexturedMesh = null; if (haircutIdentity != null) { var haircutRequest = avatarProvider.GetHaircutMeshAsync(avatarCode, haircutIdentity); yield return(Await(haircutRequest)); haircutTexturedMesh = haircutRequest.Result; } // display head DisplayHead(bodyAttachment, headTexturedMesh, haircutTexturedMesh, hairColor); // finish! FinishAvatar(); }
public void OnCameraRender(Camera cam) { shader.Disable(); if (texturedMesh == null) { Console.WriteLine("No texturedMesh attached when trying to render entity: " + entity.name); texturedMesh = entity.GetComponent <TexturedMesh>(); return; } GL.BindVertexArray(texturedMesh.GetRawMesh().GetVaoID()); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, texturedMesh.GetTexture().GetID()); shader.Enable(); shader.LoadTranformMatrix(entity.transform.GetTransformMatrix()); if (projectionMatrix == Matrix4.Identity) { UpdateProjectionMatrix(cam); return; } shader.LoadProjectionMatrix(projectionMatrix); shader.LoadViewMatrix(cam.GetViewMatrix()); GL.DrawElements(PrimitiveType.Triangles, texturedMesh.GetRawMesh().GetVertexCount(), DrawElementsType.UnsignedInt, 0); GL.DisableVertexAttribArray(0); GL.DisableVertexAttribArray(1); GL.BindVertexArray(0); }
/// <summary> /// Displays head mesh and harcut on the scene /// </summary> protected virtual void DisplayHead(TexturedMesh headMesh, TexturedMesh haircutMesh) { // create parent avatar object in a scene, attach a script to it to allow rotation by mouse var avatarObject = new GameObject("ItSeez3D Avatar"); avatarObject.AddComponent <RotateByMouse>(); // create head object in the scene Debug.LogFormat("Generating Unity mesh object for head..."); var headObject = new GameObject("HeadObject"); var headMeshRenderer = headObject.AddComponent <SkinnedMeshRenderer>(); headMeshRenderer.sharedMesh = headMesh.mesh; var headMaterial = new Material(Shader.Find("AvatarUnlitShader")); headMaterial.mainTexture = headMesh.texture; headMeshRenderer.material = headMaterial; headObject.transform.SetParent(avatarObject.transform); if (haircutMesh != null) { // create haircut object in the scene var haircutObject = new GameObject("HaircutObject"); var haircutMeshRenderer = haircutObject.AddComponent <SkinnedMeshRenderer>(); haircutMeshRenderer.sharedMesh = haircutMesh.mesh; var haircutMaterial = new Material(Shader.Find("AvatarUnlitHairShader")); haircutMaterial.mainTexture = haircutMesh.texture; haircutMeshRenderer.material = haircutMaterial; haircutObject.transform.SetParent(avatarObject.transform); } }
private Matrix4 projectionMatrix = Matrix4.Identity; //Store projection matrix for optimization public override void InitializeComponent() { Camera.OnRender += OnCameraRender; Camera.OnChange += OnCameraChange; texturedMesh = entity.GetComponent <TexturedMesh>(); shader = new BasicShader(); UpdateProjectionMatrix(Camera.GetCurrentCamera()); }
private void AddTexturedMesh(string texPath, MeshData meshData, Vector3 position, Quaternion rotation, Vector3 scale) { ImageSharpMipmapChain texData = new ImageSharpMipmapChain(AssetHelper.GetPath(texPath)); TexturedMesh mesh = new TexturedMesh(meshData, texData, CommonMaterials.Brick); mesh.Transform.Position = position; mesh.Transform.Rotation = rotation; mesh.Transform.Scale = scale; mesh.CreateDeviceObjects(_rc); _scene.AddRenderable(mesh); }
/// <summary> /// To make Getting Started sample as simple as possible all code required for creating and /// displaying an avatar is placed here in a single function. This function is also a good example of how to /// chain asynchronous requests, just like in traditional sequential code. /// </summary> protected virtual IEnumerator GenerateAndDisplayHead(byte[] photoBytes, PipelineType pipeline) { // Choose default set of resources to generate var resourcesRequest = avatarProvider.ResourceManager.GetResourcesAsync(AvatarResourcesSubset.DEFAULT, pipelineType); yield return(Await(resourcesRequest)); // generate avatar from the photo and get its code in the Result of request var initializeRequest = avatarProvider.InitializeAvatarAsync(photoBytes, "name", "description", pipeline, resourcesRequest.Result); yield return(Await(initializeRequest)); string avatarCode = initializeRequest.Result; StartCoroutine(SampleUtils.DisplayPhotoPreview(avatarCode, photoPreview)); var calculateRequest = avatarProvider.StartAndAwaitAvatarCalculationAsync(avatarCode); yield return(Await(calculateRequest)); // with known avatar code we can get TexturedMesh for head in order to show it further var avatarHeadRequest = avatarProvider.GetHeadMeshAsync(avatarCode, false); yield return(Await(avatarHeadRequest)); TexturedMesh headTexturedMesh = avatarHeadRequest.Result; TexturedMesh haircutTexturedMesh = null; // get identities of all haircuts available for the generated avatar var haircutsIdRequest = avatarProvider.GetHaircutsIdAsync(avatarCode); yield return(Await(haircutsIdRequest)); // randomly select a haircut var haircuts = haircutsIdRequest.Result; if (haircuts != null && haircuts.Length > 0) { var haircutIdx = UnityEngine.Random.Range(0, haircuts.Length); var haircut = haircuts[haircutIdx]; // load TexturedMesh for the chosen haircut var haircutRequest = avatarProvider.GetHaircutMeshAsync(avatarCode, haircut); yield return(Await(haircutRequest)); haircutTexturedMesh = haircutRequest.Result; } DisplayHead(headTexturedMesh, haircutTexturedMesh); }
private void DisplayHead(BodyAttachment bodyAttachment, TexturedMesh headMesh, TexturedMesh haircutMesh, string hairColor) { var avatarObject = new GameObject("Avatar"); // create head object in the scene SkinnedMeshRenderer headRenderer = null; if (headMesh != null) { var meshObject = new GameObject("HeadObject"); headRenderer = meshObject.AddComponent <SkinnedMeshRenderer>(); headRenderer.sharedMesh = headMesh.mesh; var material = new Material(Shader.Find("AvatarUnlitShader")); material.mainTexture = headMesh.texture; headRenderer.material = material; meshObject.transform.SetParent(avatarObject.transform); } // create haircut object in the scene if (haircutMesh != null) { var meshObject = new GameObject("HaircutObject"); var meshRenderer = meshObject.AddComponent <SkinnedMeshRenderer>(); meshRenderer.sharedMesh = haircutMesh.mesh; var material = new Material(Shader.Find("AvatarUnlitHairShader")); material.mainTexture = haircutMesh.texture; meshRenderer.material = material; if (!ChangeMeshTint(meshRenderer, hairColor)) { Debug.LogError("Error changing hair color!"); } meshObject.transform.SetParent(avatarObject.transform); } // attach head if (bodyAttachment != null) { bodyAttachment.AttachHeadToBody(avatarObject); } // change body skin color match head color if (bodyAttachment != null && headRenderer != null) { MatchTwoMeshTint(bodyAttachment.body.GetComponent <SkinnedMeshRenderer>(), headRenderer); } }
/// <summary> /// Displays head mesh and harcut on the scene /// </summary> protected virtual AvatarInfo CreateHead(string avatarCode, TexturedMesh headMesh, TexturedMesh haircutMesh) { // create parent avatar object in a scene, attach a script to it to allow rotation by mouse var avatarObject = new GameObject(AVATAR_OBJECT_NAME); // create head object in the scene Debug.LogFormat("Generating Unity mesh object for head..."); var headObject = new GameObject(HEAD_OBJECT_NAME); var headMeshRenderer = headObject.AddComponent <SkinnedMeshRenderer>(); headMeshRenderer.sharedMesh = headMesh.mesh; var headMaterial = new Material(Shader.Find("AvatarUnlitShader")) { mainTexture = headMesh.texture }; headMeshRenderer.material = headMaterial; headObject.transform.SetParent(avatarObject.transform); MeshRenderer haircutMeshRenderer = null; if (haircutMesh != null) { // create haircut object in the scene var haircutObject = new GameObject(HAIRCUT_OBJECT_NAME); MeshFilter mf = haircutObject.AddComponent <MeshFilter>(); haircutMeshRenderer = haircutObject.AddComponent <MeshRenderer>(); mf.sharedMesh = haircutMesh.mesh; var haircutMaterial = new Material(Shader.Find("AvatarUnlitHairShader")) { mainTexture = haircutMesh.texture }; haircutMeshRenderer.material = haircutMaterial; haircutObject.transform.SetParent(avatarObject.transform); } var avatarInfo = avatarObject.AddComponent <AvatarInfo>(); avatarInfo.headMeshRenderer = headMeshRenderer; avatarInfo.hairMeshRenderer = haircutMeshRenderer; avatarInfo.predictedHaircutColor = GetAvatarPredictedColor(avatarCode); if (haircutMesh != null) { avatarInfo.avgHaircutColor = CoreTools.CalculateAverageColor(haircutMeshRenderer.sharedMaterial.mainTexture as Texture2D); avatarInfo.HaircutColor = avatarInfo.predictedHaircutColor; } return(avatarInfo); }
protected override void DisplayHead(TexturedMesh headMesh, TexturedMesh haircutMesh) { if (pipelineType != PipelineType.FACE) { Debug.LogErrorFormat("Avatar from the {0} can't be used in Fullbody sample!", pipelineType); return; } // create parent avatar object in a scene, attach a script to it to allow rotation by mouse var avatarObject = new GameObject("ItSeez3D Avatar"); // create head object in the scene { Debug.LogFormat("Generating Unity mesh object for head..."); var meshObject = new GameObject("HeadObject"); var meshRenderer = meshObject.AddComponent <SkinnedMeshRenderer>(); meshRenderer.sharedMesh = headMesh.mesh; var material = new Material(Shader.Find("AvatarUnlitShader")); material.mainTexture = headMesh.texture; meshRenderer.material = material; meshObject.transform.SetParent(avatarObject.transform); } // create haircut object in the scene { var meshObject = new GameObject("HaircutObject"); var meshRenderer = meshObject.AddComponent <SkinnedMeshRenderer>(); meshRenderer.sharedMesh = haircutMesh.mesh; var material = new Material(Shader.Find("AvatarUnlitHairShader")); material.mainTexture = haircutMesh.texture; meshRenderer.material = material; meshObject.transform.SetParent(avatarObject.transform); } if (bodyAttachments == null || bodyAttachments.Length <= 0) { Debug.LogError("No body attachments specified!"); return; } foreach (var bodyAttachment in bodyAttachments) { bodyAttachment.AttachHeadToBody(GameObject.Instantiate(avatarObject)); } GameObject.Destroy(avatarObject); }
private MeshRenderer CreateHaircutObject(TexturedMesh haircutMesh, GameObject avatarObject) { // create haircut object in the scene var haircutObject = new GameObject(HAIRCUT_OBJECT_NAME); MeshFilter mf = haircutObject.AddComponent <MeshFilter>(); MeshRenderer haircutMeshRenderer = haircutObject.AddComponent <MeshRenderer>(); mf.sharedMesh = haircutMesh.mesh; var haircutMaterial = new Material(Shader.Find("AvatarUnlitHairShader")) { mainTexture = haircutMesh.texture }; haircutMeshRenderer.material = haircutMaterial; haircutObject.transform.SetParent(avatarObject.transform); return(haircutMeshRenderer); }
private void AddTexturedMesh( MeshData meshData, ImageSharpTexture texData, ImageSharpTexture alphaTexData, MaterialPropsAndBuffer materialProps, Vector3 position, Quaternion rotation, Vector3 scale, string name) { TexturedMesh mesh = new TexturedMesh(name, meshData, texData, alphaTexData, materialProps ?? CommonMaterials.Brick); mesh.Transform.Position = position; mesh.Transform.Rotation = rotation; mesh.Transform.Scale = scale; _scene.AddRenderable(mesh); }
private TexturedMesh CreateSurface(Surface surf) { Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = CreateVectorlist(surf.outerRing); if (surf.outerringUVs.Count > 0) { surf.outerringUVs.Reverse(); poly.outsideUVs = surf.outerringUVs; } ; if (surf.innerRings.Count > 0) { foreach (var innerring in surf.innerRings) { poly.holes.Add(CreateVectorlist(innerring)); } } if (surf.innerringUVs.Count > 0) { surf.innerringUVs.Reverse(); poly.holesUVs = surf.innerringUVs; } Mesh submesh = Poly2Mesh.CreateMesh(poly); TexturedMesh texturedmesh = new TexturedMesh(); texturedmesh.mesh = submesh; if (surf.surfacetexture != null) { texturedmesh.TextureName = surf.surfacetexture.path; //texturedmesh.texture = LoadTexture(surf.surfacetexture); } submesh = null; return(texturedmesh); }
private void CreateMultiBuildingMeshes(List <Building> buildings, GameObject parent) { List <TexturedMesh> Allbuildingparts = new List <TexturedMesh>(); List <TexturedMesh> buildingparts = new List <TexturedMesh>(); TexturedMesh[] materialparts; foreach (Building building in buildings) { buildingparts = CreateOneMeshBuilding(building); foreach (TexturedMesh item in buildingparts) { Allbuildingparts.Add(item); } } List <TexturedMesh> textured = new List <TexturedMesh>(); List <TexturedMesh> untextured = new List <TexturedMesh>(); if (Materialmapping != null) { materialparts = new TexturedMesh[Materialmapping.Count]; } foreach (TexturedMesh item in Allbuildingparts) { if (item.TextureName != "" && useTextures == true) { textured.Add(item); } else { untextured.Add(item); } } List <CombineInstance> ci = new List <CombineInstance>(); if (untextured.Count > 0) { foreach (TexturedMesh item in untextured) { CombineInstance cci = new CombineInstance(); cci.mesh = item.mesh; ci.Add(cci); } GameObject go = new GameObject(); go.transform.parent = parent.transform; Mesh mesh = new Mesh(); mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; mesh.CombineMeshes(ci.ToArray(), true, false); foreach (var meshHolder in ci) { GameObject.Destroy(meshHolder.mesh); } go.AddComponent <MeshFilter>().mesh = mesh; go.AddComponent <MeshRenderer>().sharedMaterial = Defaultmaterial; } if (textured.Count > 0) { List <TexturedMesh> tm = CombineTextures.MultiCombineTextures(textured); foreach (TexturedMesh item in tm) { GameObject go = new GameObject(); go.transform.parent = parent.transform; Material mat = new Material(Defaultmaterial); mat.color = new Color(1, 1, 1); mat.SetTexture("_MainTex", item.texture); go.AddComponent <MeshFilter>().mesh = item.mesh; go.AddComponent <MeshRenderer>().sharedMaterial = mat; } } }
/// <summary> /// Show avatar in the scene. Also load haircut information to allow further haircut change. /// </summary> private IEnumerator ShowAvatar(string avatarCode) { ChangeControlsInteractability(false); yield return(new WaitForSeconds(0.05f)); StartCoroutine(SampleUtils.DisplayPhotoPreview(avatarCode, photoPreview)); progressText.text = string.Empty; currentHaircut = 0; var currentAvatar = GameObject.Find(AVATAR_OBJECT_NAME); if (currentAvatar != null) { Destroy(currentAvatar); } var avatarObject = new GameObject(AVATAR_OBJECT_NAME); var headMeshRequest = avatarProvider.GetHeadMeshAsync(avatarCode, true); yield return(Await(headMeshRequest)); if (headMeshRequest.IsError) { Debug.LogError("Could not load avatar from disk!"); } else { TexturedMesh texturedMesh = headMeshRequest.Result; // game object can be deleted if we opened another avatar if (avatarObject != null && avatarObject.activeSelf) { avatarObject.AddComponent <RotateByMouse>(); headObject = new GameObject(HEAD_OBJECT_NAME); var meshRenderer = headObject.AddComponent <SkinnedMeshRenderer>(); meshRenderer.sharedMesh = texturedMesh.mesh; meshRenderer.material = IsUnlitMode ? unlitMaterial : litMaterial; meshRenderer.material.mainTexture = texturedMesh.texture; headObject.transform.SetParent(avatarObject.transform); SetAvatarScale(avatarCode, avatarObject.transform); if (useAnimations) { if (isWebGLDemo) { // don't show all animations in webgl demo GetComponent <AnimationManager>().CreateAnimator(headObject, animations.GetRange(0, 5)); } else { GetComponent <AnimationManager>().CreateAnimator(headObject, animations); } } else { //add an empty blendshape with index -1 availableBlendshapes.Add(-1, "None"); var mesh = headObject.GetComponentInChildren <SkinnedMeshRenderer>().sharedMesh; for (int i = 0; i < mesh.blendShapeCount; i++) { availableBlendshapes.Add(i, mesh.GetBlendShapeName(i)); } ChangeCurrentBlendshape(-1); blendshapesSelectingView.InitItems(availableBlendshapes.Values.ToList()); if (availableBlendshapes.Count == 1) { blendshapesPanel.SetActive(false); } } } } var haircutsIdsRequest = GetHaircutsIdsAsync(avatarCode); yield return(haircutsIdsRequest); string[] haircuts = haircutsIdsRequest.Result; if (haircuts != null && haircuts.Length > 0) { //Add fake "bald" haircut var haircutsList = haircuts.ToList(); haircutsList.Insert(0, BALD_HAIRCUT_NAME); avatarHaircuts = haircutsList.ToArray(); OnDisplayedHaircutChanged(avatarHaircuts[currentHaircut]); haircutsSelectingView.InitItems(avatarCode, avatarHaircuts.ToList(), avatarProvider); haircutsPanel.SetActive(true); } else { haircutsPanel.SetActive(false); OnDisplayedHaircutChanged(BALD_HAIRCUT_NAME); } ChangeControlsInteractability(true); avatarControls.SetActive(true); }
private TexturedMesh CreateSurface(Surface surf, GameObject parentGameobject = null) { Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = CreateVectorlist(surf.outerRing, Origin); if (surf.outerringUVs.Count > 0) { poly.outsideUVs = surf.outerringUVs; } ; if (surf.innerRings.Count > 0) { foreach (var innerring in surf.innerRings) { poly.holes.Add(CreateVectorlist(innerring, Origin)); } } if (surf.innerringUVs.Count > 0) { poly.holesUVs = surf.innerringUVs; } Mesh submesh = Poly2Mesh.CreateMesh(poly); if (parentGameobject != null) { GameObject go = new GameObject(); for (int i = 0; i < surf.semantics.Count; i++) { if (surf.semantics[i].name == "type") { go.name = surf.semantics[i].value; i = surf.semantics.Count; } } if (submesh != null) { go.transform.parent = parentGameobject.transform; go.AddComponent <MeshFilter>().sharedMesh = submesh; go.AddComponent <MeshRenderer>().sharedMaterial = Defaultmaterial; ObjectProperties op = go.AddComponent <ObjectProperties>(); op.semantics = surf.semantics; if (surf.surfacetexture != null && useTextures == true) { Material mat = new Material(Defaultmaterial); mat.color = new Color(1, 1, 1); mat.SetTexture("_MainTex", LoadTexture(surf.surfacetexture)); go.GetComponent <MeshRenderer>().material = mat; } } } else { TexturedMesh texturedmesh = new TexturedMesh(); for (int i = 0; i < surf.semantics.Count; i++) { if (surf.semantics[i].name == "name") { texturedmesh.IdentifierString = surf.semantics[i].value; } } texturedmesh.mesh = submesh; if (surf.surfacetexture != null) { texturedmesh.TextureName = surf.surfacetexture.path; texturedmesh.texture = LoadTexture(surf.surfacetexture); } return(texturedmesh); } return(null); }
private IEnumerator ShowAvatarByCode(string avatarCode) { // with known avatar code we can get TexturedMesh for head in order to show it further var avatarHeadRequest = avatarProvider.GetHeadMeshAsync(avatarCode, true); yield return(AwaitRoutine(avatarHeadRequest)); TexturedMesh headTexturedMesh = avatarHeadRequest.Result; TexturedMesh haircutTexturedMesh = null; // get identities of all haircuts available for the generated avatar var haircutsIdRequest = avatarProvider.GetHaircutsIdAsync(avatarCode); yield return(AwaitRoutine(haircutsIdRequest)); ModelInfo modelInfo = CoreTools.GetAvatarModelInfo(avatarCode); // select predicted haircut var haircuts = haircutsIdRequest.Result.ToList(); var haircutIdx = 0; if (haircuts != null && haircuts.Count > 0 && !string.IsNullOrEmpty(modelInfo.haircut_name)) { haircutIdx = haircuts.FindIndex(h => h.Contains(modelInfo.haircut_name)); if (haircutIdx >= 0) { // load TexturedMesh for the chosen haircut var haircutRequest = avatarProvider.GetHaircutMeshAsync(avatarCode, haircuts[haircutIdx]); yield return(AwaitRoutine(haircutRequest)); haircutTexturedMesh = haircutRequest.Result; } } var avatarInfo = CreateHead(avatarCode, headTexturedMesh, haircutTexturedMesh, modelInfo); avatarInfo.code = avatarCode; avatarInfo.name = ReadAvatarNameByCode(avatarCode); avatarInfo.haircuts = haircutsIdRequest.Result; avatarInfo.selectedHairstyle = haircutIdx; avatarInfo.transform.position = Vector3.zero; avatarInfo.transform.localRotation = Quaternion.identity; Selection.activeGameObject = avatarInfo.gameObject; SceneView sceneView = SceneView.lastActiveSceneView; if (sceneView == null) { Type GameViewType = System.Type.GetType("UnityEditor.GameView,UnityEditor"); sceneView = EditorWindow.GetWindow <SceneView>(new Type[] { GameViewType }); } if (sceneView != null) { Camera sceneCam = sceneView.camera; sceneView.pivot = Vector3.zero; sceneView.size = cameraOffset; sceneView.LookAt(Vector3.zero, Quaternion.identity); } Tools.current = Tool.Rotate; }
public RenderableEntity(Transform transform, TexturedMesh mesh) { this.Transform = transform; this.Mesh = mesh; }
private void CreateOneMeshBuildingObject(Building building, GameObject parent) { List <TexturedMesh> buildingparts = new List <TexturedMesh>(); buildingparts = CreateOneMeshBuilding(building); List <TexturedMesh> textured = new List <TexturedMesh>(); List <TexturedMesh> untextured = new List <TexturedMesh>(); foreach (TexturedMesh item in buildingparts) { if (item.TextureName != "" && useTextures == true) { textured.Add(item); } else { untextured.Add(item); } } GameObject go = new GameObject(); Material mat = new Material(Defaultmaterial); go.AddComponent <ObjectProperties>().semantics = building.semantics; go.name = go.name = GetBuildingID(building); List <CombineInstance> ci = new List <CombineInstance>(); if (untextured.Count > 0) { foreach (TexturedMesh item in untextured) { CombineInstance cci = new CombineInstance(); cci.mesh = item.mesh; ci.Add(cci); } } go.transform.parent = parent.transform; if (textured.Count > 0) { TexturedMesh tm = CombineTextures.CombineMeshes(textured); if (tm != null) { CombineInstance cci = new CombineInstance(); cci.mesh = tm.mesh; ci.Add(cci); mat.color = new Color(1, 1, 1); mat.SetTexture("_MainTex", tm.texture); } } Mesh mesh = new Mesh(); mesh.CombineMeshes(ci.ToArray(), true, false); foreach (var meshHolder in ci) { GameObject.Destroy(meshHolder.mesh); } go.AddComponent <MeshFilter>().sharedMesh = mesh; var renderer = go.AddComponent <MeshRenderer>(); renderer.material = mat; renderer.enabled = enableRenderers; }