Last active
June 18, 2019 00:27
-
-
Save ronyx69/a5fd0eb2627131de12cd21878fa320be to your computer and use it in GitHub Desktop.
Script for deleting the automatically generated base mesh for buildings or building sub meshes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deletes automatically generated base mesh based on vertex colors. | |
// Changes shader to NoBase, enables noBase boolean, raises or lowers vertices too close to 0. | |
var subMesh = -1; // sub mesh id, order as in ui, starting from 0 (-1 means main building mesh) | |
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo; | |
var m = asset.m_mesh; var shader = Shader.Find("Custom/Buildings/Building/NoBase"); var newVertCount = 0; | |
if(subMesh >= 0) { m = asset.m_subMeshes[subMesh].m_subInfo.m_mesh; | |
if(asset.m_subMeshes[subMesh].m_subInfo.m_material != null) asset.m_subMeshes[subMesh].m_subInfo.m_material.shader = shader; | |
if(asset.m_subMeshes[subMesh].m_subInfo.m_lodMaterial != null) asset.m_subMeshes[subMesh].m_subInfo.m_lodMaterial.shader = shader; | |
asset.m_subMeshes[subMesh].m_subInfo.m_noBase = true; } | |
else { if(asset.m_material != null) asset.m_material.shader = shader; | |
if(asset.m_lodMaterial != null) asset.m_lodMaterial.shader = shader; | |
asset.m_noBase = true; } | |
if(m.colors.Length != 0) { for(var i = 0; i < m.colors.Length; i++) if(m.colors[i] == Color.white && newVertCount == 0) newVertCount = i; | |
if(newVertCount != 0) { var triCount = m.triangles.Length; var newTriCount = triCount; for(var i = 0; i < triCount; i += 3) | |
if(m.triangles[i] >= newVertCount || m.triangles[i+1] >= newVertCount || m.triangles[i+2] >= newVertCount) newTriCount-=3; | |
var newTris = new Int32[newTriCount]; for(var i = 0; i < triCount; i += 3) { | |
if(m.triangles[i] >= newVertCount || m.triangles[i+1] >= newVertCount || m.triangles[i+2] >= newVertCount) continue; | |
newTris[i] = m.triangles[i]; newTris[i+1] = m.triangles[i+1]; newTris[i+2] = m.triangles[i+2]; } | |
var newVerts = new Vector3[newVertCount]; for(var i = 0; i < newVertCount; i++) { | |
if(m.vertices[i].y < 0.06f && m.vertices[i].y > -0.06f) { | |
if(m.vertices[i].y > 0) newVerts[i] = new Vector3(m.vertices[i].x, 0.06f, m.vertices[i].z); | |
else newVerts[i] = new Vector3(m.vertices[i].x, -0.06f, m.vertices[i].z); } | |
else newVerts[i] = m.vertices[i]; } | |
var newNormals = new Vector3[newVertCount]; for(var i = 0; i < newVertCount; i++) newNormals[i] = m.normals[i]; | |
var newTangents = new Vector4[newVertCount]; for(var i = 0; i < newVertCount; i++) newTangents[i] = m.tangents[i]; | |
var newColors = new Color[newVertCount]; for(var i = 0; i < newVertCount; i++) newColors[i] = m.colors[i]; | |
var newColors32 = new Color32[newVertCount]; for(var i = 0; i < newVertCount; i++) newColors32[i] = m.colors32[i]; | |
m.triangles = newTris; m.vertices = newVerts; m.normals = newNormals; m.tangents = newTangents; m.colors = newColors; } } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment