<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — replace building mesh with a new one]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=423</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=423&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in replace building mesh with a new one.]]></description>
		<lastBuildDate>Sun, 19 Feb 2017 22:01:36 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: replace building mesh with a new one]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1853#p1853</link>
			<description><![CDATA[<p>Hello.</p><p>You can get the size of the original building from the collider (GetComponent&lt;Collider&gt;().bounds), and calculate the scale. <br />But there is a small problem - when you change the zoom, you will lose your scale. So it is better to do in this way:<br /></p><div class="codebox"><pre><code>//in Start
buildingsControl.OnBuildingCreated += OnBuildingCreated;

private void OnBuildingCreated (OnlineMapsBuildingBase building)
{
        var gMesh = debris1.GetComponent&lt;MeshFilter&gt;();
        var mesh = building.GetComponent&lt;MeshFilter&gt;();

//detect building volume
        var size = VolumeOfMesh(mesh.mesh);
        if (size &lt; 200000)
        {
            Collider cl = building.GetComponent&lt;Collider&gt;();
            Vector3 scale = CalculateScale(cl.bounds);
            OnlineMapsUtils.DestroyImmediate(building.GetComponent&lt;MeshRenderer&gt;());
            OnlineMapsUtils.DestroyImmediate(mesh);
            OnlineMapsUtils.DestroyImmediate(cl);
            GameObject newBuilding = Instantiate(debris1);
            newBuilding.transform.parent = building.transform;
            newBuilding.transform.localPosition = Vector3.zero;
            newBuilding.transform.localRotation = Quaternion.Euler(Vector3.zero);
            newBuilding.transform.localScale = scale;
        }
        return true;
}</code></pre></div><p>P.S. This code is a theoretical and I haven&#039;t tested it.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sun, 19 Feb 2017 22:01:36 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1853#p1853</guid>
		</item>
		<item>
			<title><![CDATA[replace building mesh with a new one]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1850#p1850</link>
			<description><![CDATA[<p>Hi,</p><p>I am working on the function to&nbsp; replace the building meshes with a kind of &#039;debris&#039; meshes (created in Blender).<br />I made function to detect small buildings:<br /></p><div class="codebox"><pre><code>//in Start     
   buildingsControl.OnShowBuilding = OnShowBuilding;


 private bool OnShowBuilding(OnlineMapsBuildingBase onlineMapsBuildingBase)
    {
        var gMesh = debris1.GetComponent&lt;MeshFilter&gt;();
        var mesh = onlineMapsBuildingBase.GetComponent&lt;MeshFilter&gt;();

//detect building volume
        var size = VolumeOfMesh(mesh.mesh);
        if (size &lt; 200000)
        {
//replace (bad way)
            mesh.mesh = gMesh.sharedMesh;
        }
        return true;
    }</code></pre></div><p>I get an expected result.&nbsp; But the new mesh is not of the previous building size and scale (apparently it is of its initial prefab size).</p><p>Could you please sugest a better way or idea to do this?</p>]]></description>
			<author><![CDATA[null@example.com (DolceVita)]]></author>
			<pubDate>Sat, 18 Feb 2017 20:13:15 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1850#p1850</guid>
		</item>
	</channel>
</rss>
