From 1abd60e48f47d675124be8331b564e9a11acf642 Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Sat, 21 Sep 2024 02:14:24 +0200 Subject: [PATCH] Blend format: load some custom properties in objects. --- src/loaders/blend.nim | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/loaders/blend.nim b/src/loaders/blend.nim index 5988ebc..31ce6be 100644 --- a/src/loaders/blend.nim +++ b/src/loaders/blend.nim @@ -44,7 +44,7 @@ import std/strutils import std/strformat import std/bitops import std/options -# import std/tables +import std/json import vmath except Quat import ../quat @@ -262,7 +262,32 @@ proc makeMaterialAndTextures(self: BlendLoader; except Exception as e: echo "Material: ", bmat.id.name.str.strip2 raise e - + +proc idPropertiesToJsonTable(prop: FNode): Table[string, JsonNode] = + var prop = prop + while prop.valid: + let name = prop.name.str + let val = prop.data.val.i32[0] + var cstr: cstring = "" + if prop.data["pointer"].valid: + var p = prop.data["pointer"] + p.set_type("char") + cstr = p.cstr + case prop["type"].i8[0] + of 0: # string + result[name] = %($cstr) + of 1: # int + result[name] = %val + of 5: # array + let subtype = prop.subtype.i8[0] + of 8: # float + let f = cast[ptr float64](prop.data.val.i32[0].addr)[] + result[name] = %f + of 10: # bool + result[name] = %bool(val) + else: discard + prop = prop.next + proc loadObjectImpl(self: BlendLoader, scene: Scene, obn: FNode): (GameObject, string) = let name = obn.id.name.str.strip2 let data = obn.data @@ -479,6 +504,10 @@ proc loadObjectImpl(self: BlendLoader, scene: Scene, obn: FNode): (GameObject, s ob.visible = (restrictflag and 4) == 0 ob.object_color = obn.col.f32.vec4 + + let prop = obn.id.properties + if prop.valid: + ob.properties = idPropertiesToJsonTable(prop.data.group.first) return (ob, parent_name)