Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copy vertex paint from prop to vehicle sub mesh, use rotors shader on a vehicle sub mesh, adjust shader and tyre parameters.
// reminder: the y axis ingame represents height
// (as opposed to z, usually used in 3d software)
// vertex color explanation
// RED for blimps(visibility): 0 visible when spinning, 255 visible when stopped
// RED for bus(visibility): 0 visible when blinkers on, 255 always visible
// IDK what red will do on other vehicles
// GREEN(tyre parameter vector id multiplied by 8): color 0 uses 0, 8 uses 1, 16 uses 2, 24 uses 3 etc.
// BLUE(axis): 0 y axis, 255 x or z axis (if shader float _FlipTyreRotationXZ = 1)
//
// for vehicles, vertex colors get generated and overwritten on import
// therefore you need to import the rotors sub mesh as a prop, save, reload
// and then import the vehicle sub mesh,
// and copy the vertex paint from the prop to the vehicle sub mesh using this script:
var subMesh = 1; // vehicle sub mesh id, starting from 1
var asset2 = PrefabCollection<PropInfo>.FindLoaded("filename.Asset Name_Data"); // CHANGE TO PROP NAME
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as VehicleInfo;
Color[] colors = new Color[asset2.m_mesh.vertices.Length];
for (int i = 0; i < asset2.m_mesh.vertices.Length; i++) colors[i] = asset2.m_mesh.colors[i];
asset.m_subMeshes[subMesh].m_subInfo.m_mesh.colors = colors;
//
// vehicle sub mesh rotors shader and tyre parameters
var subMesh = 1; // vehicle sub mesh id, starting from 1
var flipxz = 0.0f; // shader float _FlipTyreRotationXZ, doesn't save, use Rotors FlipXZ mod
var tyres = 2; // amount of "tyres"
Vector4[] tyreParams = new Vector4[tyres];
// tyre parameter vectors:
tyreParams[0] = new Vector4(0.0f, 7.0f, 0.0f, 0.0f); // pivot x, y, z, radius(doesn't affect anything)
tyreParams[1] = new Vector4(0.0f, 9.0f, 5.0f, 0.0f); // however many "tyres" you need
//tyreParams[2] = new Vector4(2.0f, 4.0f, 1.0f, 0.0f);
//tyreParams[3] = new Vector4(2.0f, 4.0f, 1.0f, 0.0f);
var shader = Shader.Find("Custom/Vehicles/Vehicle/Rotors");
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as VehicleInfo;
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_material.SetFloat("_FlipTyreRotationXZ", flipxz);
asset.m_subMeshes[subMesh].m_subInfo.m_generatedInfo.m_tyres = tyreParams;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment