Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copies mesh from a prop to a vehicle, don't use for vehicles with tyres.
// Copies mesh from a prop to a vehicle, don't use for vehicles with tyres.
var propname = "filename.Asset Name"; // filename.Asset Name
var prop = PrefabCollection<PropInfo>.FindLoaded(propname + "_Data");
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as VehicleInfo;
asset.m_mesh.vertices = prop.m_mesh.vertices; asset.m_mesh.triangles = prop.m_mesh.triangles;
asset.m_mesh.tangents = prop.m_mesh.tangents; asset.m_mesh.normals = prop.m_mesh.normals;
asset.m_mesh.uv = prop.m_mesh.uv; asset.m_mesh.bounds = prop.m_mesh.bounds;
asset.m_generatedInfo.m_size = prop.m_generatedInfo.m_size;
asset.m_generatedInfo.m_triangleArea = prop.m_generatedInfo.m_triangleArea;
asset.m_generatedInfo.m_uvmapArea = prop.m_generatedInfo.m_uvmapArea;
asset.m_generatedInfo.m_wheelBase = asset.m_generatedInfo.m_size.z * 0.6f;
asset.m_generatedInfo.m_wheelGauge = asset.m_generatedInfo.m_size.x * 0.5f;
if(asset.m_mesh.bounds.min.y < 0) asset.m_generatedInfo.m_negativeHeight = Math.Abs(asset.m_mesh.bounds.min.y);
else asset.m_generatedInfo.m_negativeHeight = 0;
Color nc = new Color32(0, 0, 1, 1); Color32 nc32 = new Color32(0, 0, 255, 255);
var colors = new Color[asset.m_mesh.vertices.Length]; var colors32 = new Color32[asset.m_mesh.vertices.Length];
for(var i = 0; i < asset.m_mesh.vertices.Length; i++) { colors[i] = nc; colors32[i] = nc32; }
asset.m_mesh.colors = colors; asset.m_mesh.colors32 = colors32;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.