Blend format: load some custom properties in objects.

This commit is contained in:
Alberto Torres 2024-09-21 02:14:24 +02:00
parent 61c1986c92
commit 1abd60e48f

View file

@ -44,7 +44,7 @@ import std/strutils
import std/strformat import std/strformat
import std/bitops import std/bitops
import std/options import std/options
# import std/tables import std/json
import vmath except Quat import vmath except Quat
import ../quat import ../quat
@ -262,7 +262,32 @@ proc makeMaterialAndTextures(self: BlendLoader;
except Exception as e: except Exception as e:
echo "Material: ", bmat.id.name.str.strip2 echo "Material: ", bmat.id.name.str.strip2
raise e 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) = proc loadObjectImpl(self: BlendLoader, scene: Scene, obn: FNode): (GameObject, string) =
let name = obn.id.name.str.strip2 let name = obn.id.name.str.strip2
let data = obn.data 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.visible = (restrictflag and 4) == 0
ob.object_color = obn.col.f32.vec4 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) return (ob, parent_name)