Blend format: load some custom properties in objects.
This commit is contained in:
parent
61c1986c92
commit
1abd60e48f
|
@ -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
|
||||
|
||||
|
@ -263,6 +263,31 @@ proc makeMaterialAndTextures(self: BlendLoader;
|
|||
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
|
||||
|
@ -480,6 +505,10 @@ proc loadObjectImpl(self: BlendLoader, scene: Scene, obn: FNode): (GameObject, s
|
|||
|
||||
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)
|
||||
|
||||
proc loadSceneImpl(self: BlendLoader, scn: FNode, scene: Scene) =
|
||||
|
|
Loading…
Reference in a new issue