"""Study only: the space under the canopy at the bow (command deck), as numbers.""" import json import os import sys import bpy import numpy as np sys.dont_write_bytecode = True HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import shipfit # noqa: E402 NAMES = ["M_SHIP_Hull", "M_SHIP_Dorsal_Roof", "M_SHIP_Canopy"] fit = shipfit.Fit(NAMES) out = {"side": {}, "ceil": {}, "objects": {}} for x in (28.0, 31.0, 33.0, 35.0, 36.0, 37.0, 39.0, 41.0, 43.0, 45.0, 47.0, 49.0, 51.0, 53.0, 55.0, 57.0, 58.5): rows = [] for z in (3.2, 3.6, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5): row = [z] for n in NAMES: v = fit.side_y(x, z, 1, (n,)) row.append(None if v is None else round(v, 2)) rows.append(row) out["side"][str(x)] = rows out["ceil"][str(x)] = [[y] + [None if fit.ceil_z(x, y, 3.3, (n,)) is None else round(fit.ceil_z(x, y, 3.3, (n,)), 2) for n in NAMES] for y in (0.0, 1.5, 3.0, 4.5, 6.0, 7.5)] for n in NAMES + ["Deck | bridge"]: ob = bpy.data.objects.get(n) if ob is None: continue me = ob.data co = np.empty(len(me.vertices) * 3) me.vertices.foreach_get("co", co) m = np.array(ob.matrix_world) v = co.reshape(-1, 3) @ m[:3, :3].T + m[:3, 3] rec = {"min": [round(float(c), 2) for c in v.min(0)], "max": [round(float(c), 2) for c in v.max(0)], "faces": len(me.polygons), "materials": [s.material.name if s.material else None for s in ob.material_slots], "modifiers": [(mm.name, mm.type) for mm in ob.modifiers]} out["objects"][n] = rec mat = bpy.data.materials.get(out["objects"].get("M_SHIP_Canopy", {}).get("materials", [None])[0] or "") if mat: rec = {"name": mat.name, "blend": getattr(mat, "surface_render_method", None), "backface": mat.use_backface_culling, "nodes": []} if mat.node_tree: for nd in mat.node_tree.nodes: if nd.bl_idname == "ShaderNodeBsdfPrincipled": rec["principled"] = {i.name: (list(i.default_value) if hasattr(i.default_value, "__len__") else i.default_value) for i in nd.inputs if i.name in ("Base Color", "Alpha", "Transmission Weight", "Roughness", "Metallic", "IOR")} rec["nodes"].append(nd.bl_idname) out["canopy_material"] = rec with open(os.path.join(HERE, "study_bow.json"), "w", encoding="utf-8") as f: json.dump(out, f, indent=1) print("STUDY written")