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>
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -6,6 +7,9 @@ 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/");
|
||||
@ -21,7 +25,7 @@ namespace GrassCutter.EditorTools
|
||||
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") || (pack && !assetPath.Contains("SM_Veh_") && !assetPath.Contains("Hay_Bale"));
|
||||
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;
|
||||
|
||||
@ -256,6 +256,8 @@ namespace GrassCutter.EditorTools
|
||||
case PieceId.Garage:
|
||||
go.AddComponent<Garage>();
|
||||
ShedParts(go, model, d.scale);
|
||||
// the roof as it is drawn, above the bays: the walls and posts are boxes, the door opens
|
||||
Hull(go.transform, model, "Hull_Garage", 2.75f * d.scale, "SM_Bld_Garage_01_Door");
|
||||
break;
|
||||
case PieceId.UnloadBay:
|
||||
{
|
||||
@ -329,6 +331,8 @@ namespace GrassCutter.EditorTools
|
||||
{
|
||||
plinth.transform.localPosition = new Vector3(0f, 1.6f, 0f);
|
||||
plinth.size = new Vector3(d.sizeX - 0.2f, 3.2f, d.sizeZ - 0.2f);
|
||||
// the tower and its cap above the plinth, as drawn; the sails turn, so they stay out of it
|
||||
Hull(go.transform, model, "Hull_Windmill", 3.0f, "Spin");
|
||||
}
|
||||
var machine = go.AddComponent<Machine>();
|
||||
machine.lamp = Part<Renderer>(model, "Lamp");
|
||||
@ -380,6 +384,8 @@ namespace GrassCutter.EditorTools
|
||||
// one slope from the eave at the front (+Z) to the ridge 1.5 m up at the back
|
||||
var slope = Box(go.transform, "Slope", new Vector3(0f, 0.75f, 0f), new Vector3(3.2f, 0.16f, 3.4f), null);
|
||||
slope.transform.localRotation = Quaternion.Euler(Mathf.Atan2(1.5f, 3f) * Mathf.Rad2Deg, 0f, 0f);
|
||||
// and the roof as drawn, eaves and overhang and all: the slab alone let a body into the roof's underside
|
||||
Hull(go.transform, model, "Hull_Roof");
|
||||
break;
|
||||
}
|
||||
case PieceId.Stairs:
|
||||
@ -516,6 +522,61 @@ namespace GrassCutter.EditorTools
|
||||
|
||||
// ───────────────────────── helpers ─────────────────────────
|
||||
|
||||
const string HullDir = "Assets/Art/Colliders";
|
||||
|
||||
/// <summary>
|
||||
/// A collider in the model's own shape, for what boxes don't follow: a roof's slopes and overhang, a windmill's
|
||||
/// tower above its plinth, a cabin's gable. Only triangles reaching above minY (in root space) are kept, and parts
|
||||
/// named in skip (sails that turn, doors that open) are left out. The mesh is saved beside the prefabs.
|
||||
/// </summary>
|
||||
public static MeshCollider Hull(Transform root, Transform model, string asset, float minY = float.NegativeInfinity, params string[] skip) => Hull(root, model, asset, minY, float.PositiveInfinity, skip);
|
||||
|
||||
/// <summary>Only triangles lying wholly below maxY too: a chimney left out of a roof's convex hull.</summary>
|
||||
public static MeshCollider Hull(Transform root, Transform model, string asset, float minY, float maxY, params string[] skip)
|
||||
{
|
||||
var verts = new List<Vector3>();
|
||||
var tris = new List<int>();
|
||||
var toRoot = root.worldToLocalMatrix;
|
||||
foreach (var mf in model.GetComponentsInChildren<MeshFilter>(true))
|
||||
{
|
||||
if (!mf.sharedMesh) continue;
|
||||
bool skipped = false;
|
||||
for (var t = mf.transform; t && t != root; t = t.parent)
|
||||
if (skip.Contains(t.name)) { skipped = true; break; }
|
||||
if (skipped) continue;
|
||||
var m = mf.sharedMesh;
|
||||
var to = toRoot * mf.transform.localToWorldMatrix;
|
||||
int b = verts.Count;
|
||||
foreach (var v in m.vertices) verts.Add(to.MultiplyPoint3x4(v));
|
||||
var tr = m.triangles;
|
||||
for (int i = 0; i < tr.Length; i += 3)
|
||||
{
|
||||
int i0 = b + tr[i], i1 = b + tr[i + 1], i2 = b + tr[i + 2];
|
||||
if (Mathf.Max(verts[i0].y, Mathf.Max(verts[i1].y, verts[i2].y)) < minY || Mathf.Max(verts[i0].y, Mathf.Max(verts[i1].y, verts[i2].y)) > maxY) continue;
|
||||
tris.Add(i0); tris.Add(i1); tris.Add(i2);
|
||||
}
|
||||
}
|
||||
if (tris.Count == 0) return null;
|
||||
var mesh = new Mesh { name = asset };
|
||||
if (verts.Count > 65000) mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
|
||||
mesh.SetVertices(verts);
|
||||
mesh.SetTriangles(tris, 0);
|
||||
mesh.RecalculateBounds();
|
||||
if (!AssetDatabase.IsValidFolder(HullDir)) AssetDatabase.CreateFolder("Assets/Art", "Colliders");
|
||||
var path = HullDir + "/" + asset + ".asset";
|
||||
var old = AssetDatabase.LoadAssetAtPath<Mesh>(path);
|
||||
if (old) { EditorUtility.CopySerialized(mesh, old); mesh = old; EditorUtility.SetDirty(old); }
|
||||
else AssetDatabase.CreateAsset(mesh, path);
|
||||
var go = new GameObject("Hull");
|
||||
go.transform.SetParent(root, false);
|
||||
var mc = go.AddComponent<MeshCollider>();
|
||||
mc.sharedMesh = mesh;
|
||||
// convex: a body pushed out of a bare triangle mesh can be pushed out the wrong side (through the roof); a roof,
|
||||
// a gable and a tower above its plinth are all near enough convex for that
|
||||
mc.convex = true;
|
||||
return mc;
|
||||
}
|
||||
|
||||
static PhysicsMaterial PhysMat(string name, float stat, float dyn, float bounce)
|
||||
{
|
||||
var path = Prefabs + name + ".physicMaterial";
|
||||
|
||||
@ -167,6 +167,8 @@ namespace GrassCutter.EditorTools
|
||||
ground.spires = new[] { Model("SM_Spire_A"), Model("SM_Spire_B"), Model("SM_Spire_C") };
|
||||
ground.trees = new[] { Model("SM_Generic_Tree_01"), Model("SM_Generic_Tree_02"), Model("SM_Generic_Tree_03") };
|
||||
ground.bush = Model("SM_Prop_Plant_Bush_03_L");
|
||||
ground.stones = new[] { Model("SM_Boulders"), Model("SM_SlabStones"), Model("SM_Crystals") };
|
||||
ground.growths = new[] { Model("SM_Shrooms"), Model("SM_Stump"), Model("SM_BulbPlants") };
|
||||
|
||||
var deck = new GameObject("Deck").AddComponent<DeckManager>();
|
||||
deck.tileModel = Model("SM_DeckTile");
|
||||
@ -193,7 +195,10 @@ namespace GrassCutter.EditorTools
|
||||
var cabin = Place("SM_CrewCabin", new Vector3(-6f, 0f, 7f), 180f, rig);
|
||||
if (cabin)
|
||||
{
|
||||
SolidAt("CabinBox", new Vector3(0f, 1.6f, 0f), new Vector3(5.8f, 3.2f, 3.8f), cabin.transform);
|
||||
// the walls up to the eaves (2.6 m) as a box, the roof above them as drawn (the box used to stand 0.6 m
|
||||
// proud of the eaves, and a body landed inside the roof)
|
||||
SolidAt("CabinBox", new Vector3(0f, 1.3f, 0f), new Vector3(5.8f, 2.6f, 3.8f), cabin.transform);
|
||||
Hull(cabin.transform, cabin.transform, "Hull_CrewCabin", 2.4f, 3.7f); // the chimney stays out of it
|
||||
Blocker(cabin, Vector3.zero, new Vector2(5.8f, 3.8f));
|
||||
}
|
||||
|
||||
@ -352,6 +357,8 @@ namespace GrassCutter.EditorTools
|
||||
{
|
||||
var go = Place(model, pos, yaw, rig);
|
||||
if (!go) return;
|
||||
// where the floor is, in the world: pos is the rig's, the bounds are the world's
|
||||
float floor = go.transform.position.y;
|
||||
go.transform.localScale *= scale;
|
||||
// pack props are not all pivoted at their base (the hay bale sits at its middle): stand the lowest point on the floor
|
||||
var rs = go.GetComponentsInChildren<Renderer>();
|
||||
@ -359,7 +366,7 @@ namespace GrassCutter.EditorTools
|
||||
{
|
||||
var b = rs[0].bounds;
|
||||
foreach (var r in rs) b.Encapsulate(r.bounds);
|
||||
float sink = pos.y - b.min.y;
|
||||
float sink = floor - b.min.y;
|
||||
if (sink > 0.01f) go.transform.position += Vector3.up * sink;
|
||||
}
|
||||
SolidAt("Solid", new Vector3(0f, height * 0.5f, 0f), new Vector3(size, height, size), go.transform);
|
||||
|
||||
Reference in New Issue
Block a user