From e96f70d88fcecafb2b9c0aa36d177b1c0fb3ff22 Mon Sep 17 00:00:00 2001 From: bloeys Date: Fri, 19 Nov 2021 13:40:09 +0400 Subject: [PATCH] Parse materials --- asig/asig.go | 38 ++++++++++++++++++++++++++++++++++++++ asig/material.go | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/asig/asig.go b/asig/asig.go index de30424..0cc28be 100755 --- a/asig/asig.go +++ b/asig/asig.go @@ -74,6 +74,7 @@ func parseScene(cs *C.struct_aiScene) *Scene { s := &Scene{} s.Flags = SceneFlag(cs.mFlags) s.Meshes = parseMeshes(cs.mMeshes, uint(cs.mNumMeshes)) + s.Materials = parseMaterials(cs.mMaterials, uint(cs.mNumMaterials)) return s } @@ -339,3 +340,40 @@ func parseColors(cv *C.struct_aiColor4D, count uint) []gglm.Vec4 { return verts } + +func parseMaterials(cMatsIn **C.struct_aiMaterial, count uint) []*Material { + + mats := make([]*Material, count) + cMats := unsafe.Slice(cMatsIn, count) + + for i := 0; i < int(count); i++ { + + mats[i] = &Material{ + Properties: parseMatProperties(cMats[i].mProperties, uint(cMats[i].mNumProperties)), + AllocatedStorage: uint(cMats[i].mNumAllocated), + } + } + + return mats +} + +func parseMatProperties(cMatPropsIn **C.struct_aiMaterialProperty, count uint) []*MaterialProperty { + + matProps := make([]*MaterialProperty, count) + cMatProps := unsafe.Slice(cMatPropsIn, count) + + for i := 0; i < int(count); i++ { + + cmp := cMatProps[i] + + matProps[i] = &MaterialProperty{ + name: parseAiString(cmp.mKey), + Semantic: TextureType(cmp.mSemantic), + Index: uint(cmp.mIndex), + TypeInfo: MatPropertyTypeInfo(cmp.mType), + Data: C.GoBytes(unsafe.Pointer(cmp.mData), C.int(cmp.mDataLength)), + } + } + + return matProps +} diff --git a/asig/material.go b/asig/material.go index 7e016de..38246bf 100755 --- a/asig/material.go +++ b/asig/material.go @@ -6,7 +6,7 @@ type Material struct { Properties []*MaterialProperty /** Storage allocated */ - NumAllocated uint + AllocatedStorage uint } type MaterialProperty struct {