"""Far versions of the pack's field crops: the same plant with far fewer triangles, for the ring past 30 m. And our wildflower clump: thin stems with daisy heads on a tiny palette (T_Wildflower.png), petals in its top right quarter. blender -b --factory-startup --python gc_crops.py """ import math import os import random import bmesh import bpy from mathutils import Euler, Vector PACK = r"D:\PROJECTS\ASSETS\_extract_POLYGON_Farm\flat\Models" OUT = r"D:\PROJECTS\LOCAL\GrassCutter\Assets\Art\Pack" CROPS = { "SM_Crop_Sunflower_Far": ("SM_Prop_Sunflower_02", 0.14), "SM_Crop_Corn_Far": ("SM_Prop_Plant_Corn_01_S", 0.3), } for name, (source, ratio) in CROPS.items(): bpy.ops.wm.read_factory_settings(use_empty=True) bpy.ops.import_scene.fbx(filepath=os.path.join(PACK, source + ".fbx")) o = next(x for x in bpy.context.scene.objects if x.type == "MESH") o.name = name bpy.context.view_layer.objects.active = o o.select_set(True) m = o.modifiers.new("less", "DECIMATE") m.ratio = ratio bpy.ops.object.modifier_apply(modifier=m.name) tris = sum(len(p.vertices) - 2 for p in o.data.polygons) bpy.ops.export_scene.fbx(filepath=os.path.join(OUT, name + ".fbx"), use_selection=True, axis_forward="-Z", axis_up="Y", apply_scale_options="FBX_SCALE_ALL", bake_space_transform=False, use_mesh_modifiers=True, mesh_smooth_type="FACE", add_leaf_bones=False, object_types={"MESH"}, path_mode="STRIP") print("##", name, tris, "tris") def wildflower(): GREEN, PETAL, HEART = (0.25, 0.5), (0.75, 0.75), (0.75, 0.25) bpy.ops.wm.read_factory_settings(use_empty=True) me = bpy.data.meshes.new("SM_Wildflower") bm = bmesh.new() uv = bm.loops.layers.uv.new("UVMap") def face(points, at): f = bm.faces.new([bm.verts.new(p) for p in points]) for loop in f.loops: loop[uv].uv = at rng = random.Random(11) for _ in range(7): a, d = rng.uniform(0, math.tau), rng.uniform(0.04, 0.3) foot = Vector((math.cos(a) * d, math.sin(a) * d, 0.0)) top = foot + Vector((rng.uniform(-0.08, 0.08), rng.uniform(-0.08, 0.08), rng.uniform(0.74, 1.0))) for i in range(3): s0, s1 = i / 3 * math.tau, (i + 1) / 3 * math.tau o0 = Vector((math.cos(s0), math.sin(s0), 0)) * 0.012 o1 = Vector((math.cos(s1), math.sin(s1), 0)) * 0.012 face([foot + o0, foot + o1, top + o1, top + o0], GREEN) # a leaf halfway up mid = foot.lerp(top, 0.4) out = Vector((math.cos(a + 1.2), math.sin(a + 1.2), 0.25)) * 0.14 face([mid, mid + out + Vector((0, 0, 0.05)), mid + out * 0.4 + Vector((0, 0, 0.1))], GREEN) # the head: six petals around a heart, tipped a little tilt = Euler((rng.uniform(-0.4, 0.4), rng.uniform(-0.4, 0.4), rng.uniform(0, 6))) ring = [Vector((math.cos(k / 12 * math.tau), math.sin(k / 12 * math.tau), 0)) * (0.13 if k % 2 == 0 else 0.055) for k in range(12)] ring = [top + tilt.to_matrix() @ p for p in ring] for k in range(12): face([top, ring[k], ring[(k + 1) % 12]], PETAL) lift = Vector((0, 0, 0.012)) for k in range(0, 12, 2): r0 = top + (ring[k] - top) * 0.3 + lift r1 = top + (ring[(k + 2) % 12] - top) * 0.3 + lift face([top + lift * 2, r0, r1], HEART) bm.to_mesh(me) bm.free() o = bpy.data.objects.new("SM_Wildflower", me) bpy.context.scene.collection.objects.link(o) bpy.context.view_layer.objects.active = o o.select_set(True) bpy.ops.export_scene.fbx(filepath=os.path.join(OUT, "SM_Wildflower.fbx"), use_selection=True, axis_forward="-Z", axis_up="Y", apply_scale_options="FBX_SCALE_ALL", bake_space_transform=False, use_mesh_modifiers=True, mesh_smooth_type="FACE", add_leaf_bones=False, object_types={"MESH"}, path_mode="STRIP") print("##", "SM_Wildflower", len(me.polygons), "faces") wildflower()