Files
grass-cutters/Assets/Editor/ImportRules.cs
NiemandKG 36e4bb2a10 Round 6 fixes: held tools, headlamp glare, ladder openings, level horizon, roof hulls, rain hits, idle motion, belt packs, meadow variety
- Held tools sit lower and further right; the hammer faces forward and strikes about the camera's right
- Headlamp leaves held items, treats and vending machines alone (rendering layer NoLamp); other lights keep lighting them
- Hay grounded on the floor in world space (it floated)
- Deck fence opens at each ladder, rail colliders split around it; ladders moved to 2 m off the edge middle, clear of the intakes; climbing goes over a rail only if one is in the way
- Crew stand to the soil's up (Planet.Level): flat round the base, the ball's up past it, so the horizon stays level on a small planet
- Convex roof hulls for the crew cabin, garage, pitched roof and windmill tower; cabin box lowered to the eaves
- Rain and acid rain hits differ by surface: soil, grass, wood, metal
- Idle motion: dishes pan, sways sway, sensors turn, eyes blink, windmill turns in the breeze, reels and parked rotors tick over
- Belt: take tools off at the supply wall; hold E at a vending machine for a pack of 3 on the belt, LMB has one
- New meadow pieces: boulders, slab stones, crystals, mushrooms, stump, bulb plants
- -demofix checks for all of the above; loc rows in all 11 tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 22:52:05 +06:00

135 lines
6.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Linq;
using UnityEditor;
using UnityEngine;
namespace GrassCutter.EditorTools
{
/// <summary>Import settings for Blender FBX, UI art, textures and audio.</summary>
public class ImportRules : AssetPostprocessor
{
/// <summary>The meadow's scattered stones and plants: Ground gives most of them MeshColliders at runtime.</summary>
static readonly string[] Decor = { "SM_Boulders", "SM_SlabStones", "SM_Crystals", "SM_Shrooms", "SM_Stump", "SM_BulbPlants" };
void OnPreprocessModel()
{
bool pack = assetPath.StartsWith("Assets/Art/Pack/");
if (!pack && !assetPath.StartsWith("Assets/Art/Models/")) return;
var mi = (ModelImporter)assetImporter;
mi.bakeAxisConversion = true;
mi.useFileScale = true;
mi.globalScale = 1f;
mi.importCameras = false;
mi.importLights = false;
mi.importVisibility = false;
mi.importAnimation = false;
mi.animationType = assetPath.Contains("SM_Crew") || assetPath.Contains("SM_Dir_") ? ModelImporterAnimationType.Generic : ModelImporterAnimationType.None;
mi.addCollider = false;
// runtime MeshColliders (seabed rocks and wrecks) need CPU-readable meshes in the player
mi.isReadable = assetPath.Contains("SM_Spire") || assetPath.Contains("SM_Wreck") || Decor.Any(assetPath.Contains) || (pack && !assetPath.Contains("SM_Veh_") && !assetPath.Contains("Hay_Bale"));
mi.meshCompression = ModelImporterMeshCompression.Off;
mi.importNormals = ModelImporterNormals.Import;
mi.importTangents = ModelImporterTangents.CalculateMikk;
mi.materialImportMode = ModelImporterMaterialImportMode.ImportViaMaterialDescription;
mi.materialLocation = ModelImporterMaterialLocation.InPrefab;
mi.materialSearch = ModelImporterMaterialSearch.Everywhere;
mi.materialName = ModelImporterMaterialName.BasedOnMaterialName;
}
/// <summary>
/// The Blender exports land rotated 180° about Y (fronts face −Z). Turn every model around so the manifest's
/// convention holds in Unity: front = +Z, N flap = +Z, E = +X.
/// </summary>
void OnPostprocessModel(GameObject g)
{
if (!assetPath.StartsWith("Assets/Art/Models/")) return;
g.transform.localRotation = Quaternion.AngleAxis(180f, Vector3.up) * g.transform.localRotation;
}
/// <summary>Use our hand-made URP materials (Assets/Art/Materials/M_*.mat) instead of the FBX ones.</summary>
Material OnAssignMaterialModel(Material material, Renderer renderer)
{
// the pack's atlas, and its glass as far as a name tells
if (assetPath.StartsWith("Assets/Art/Pack/"))
return AssetDatabase.LoadAssetAtPath<Material>(material.name.Contains("Glass") || renderer.name.Contains("Glass") ? "Assets/Art/Materials/M_PackGlass.mat" : "Assets/Art/Materials/M_Pack.mat");
if (!assetPath.StartsWith("Assets/Art/Models/")) return null;
var name = material.name;
int dot = name.IndexOf('.');
if (dot > 0) name = name.Substring(0, dot); // Blender duplicates: M_Foo.001
var path = "Assets/Art/Materials/" + name + ".mat";
return AssetDatabase.LoadAssetAtPath<Material>(path);
}
void OnPreprocessTexture()
{
var ti = (TextureImporter)assetImporter;
if (assetPath.StartsWith("Assets/Art/UI/"))
{
ti.textureType = TextureImporterType.Default;
ti.alphaIsTransparency = true;
ti.mipmapEnabled = false;
ti.sRGBTexture = true;
ti.wrapMode = TextureWrapMode.Clamp;
ti.maxTextureSize = 2048;
ti.textureCompression = TextureImporterCompression.CompressedHQ;
ti.npotScale = TextureImporterNPOTScale.None;
}
else if (assetPath.StartsWith("Assets/Art/Textures/"))
{
ti.textureType = TextureImporterType.Default;
ti.mipmapEnabled = true;
ti.anisoLevel = 4;
ti.wrapMode = TextureWrapMode.Repeat;
bool crew = assetPath.Contains("T_Crew_");
ti.maxTextureSize = assetPath.Contains("PolygonFarm") || crew ? 2048 : 1024;
ti.textureCompression = crew ? TextureImporterCompression.Compressed : TextureImporterCompression.CompressedHQ;
}
else if (assetPath.StartsWith("Assets/Resources/Talk/"))
{
// the rooms behind the video calls: mipmapped, so TalkHolo can take them a little out of focus
ti.textureType = TextureImporterType.Default;
ti.mipmapEnabled = true;
ti.sRGBTexture = true;
ti.wrapMode = TextureWrapMode.Clamp;
ti.maxTextureSize = 1024;
ti.textureCompression = TextureImporterCompression.CompressedHQ;
}
else if (assetPath.StartsWith("Assets/Art/Generated/"))
{
ti.textureType = TextureImporterType.Default;
ti.alphaIsTransparency = true;
ti.mipmapEnabled = true;
ti.wrapMode = TextureWrapMode.Clamp;
ti.textureCompression = TextureImporterCompression.Uncompressed;
}
}
void OnPreprocessAudio()
{
if (!assetPath.StartsWith("Assets/Audio/")) return;
var ai = (AudioImporter)assetImporter;
var s = ai.defaultSampleSettings;
bool music = assetPath.Contains("music_");
bool loop = assetPath.Contains("_loop");
if (music)
{
s.loadType = AudioClipLoadType.Streaming;
s.compressionFormat = AudioCompressionFormat.Vorbis;
s.quality = 0.75f;
}
else if (loop)
{
s.loadType = AudioClipLoadType.CompressedInMemory;
s.compressionFormat = AudioCompressionFormat.Vorbis;
s.quality = 0.8f;
}
else
{
s.loadType = AudioClipLoadType.DecompressOnLoad;
s.compressionFormat = AudioCompressionFormat.ADPCM;
}
ai.defaultSampleSettings = s;
ai.loadInBackground = music;
}
}
}