mirror of
https://github.com/bloeys/assimp-go.git
synced 2025-12-29 08:28:20 +00:00
Metadata+Fix node bug
This commit is contained in:
@ -18,7 +18,6 @@ Unimplemented (yet) AssImp Scene objects:
|
|||||||
* Animation
|
* Animation
|
||||||
* Lights
|
* Lights
|
||||||
* Camera
|
* Camera
|
||||||
* Metadata
|
|
||||||
|
|
||||||
## Using assimp-go
|
## Using assimp-go
|
||||||
|
|
||||||
|
|||||||
71
asig/asig.go
71
asig/asig.go
@ -42,7 +42,7 @@ type Node struct {
|
|||||||
* @link importer_notes @endlink page for more information on every source file
|
* @link importer_notes @endlink page for more information on every source file
|
||||||
* format. Importers that don't document any metadata don't write any.
|
* format. Importers that don't document any metadata don't write any.
|
||||||
*/
|
*/
|
||||||
Metadata *Metadata
|
Metadata map[string]Metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
type Animation struct {
|
type Animation struct {
|
||||||
@ -104,6 +104,12 @@ type Camera struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
|
Type MetadataType
|
||||||
|
Value interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MetadataEntry struct {
|
||||||
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scene struct {
|
type Scene struct {
|
||||||
@ -183,22 +189,21 @@ func parseRootNode(cNodesIn *C.struct_aiNode) *Node {
|
|||||||
Transformation: parseMat4(&cNodesIn.mTransformation),
|
Transformation: parseMat4(&cNodesIn.mTransformation),
|
||||||
Parent: nil,
|
Parent: nil,
|
||||||
MeshIndicies: parseUInts(cNodesIn.mMeshes, uint(cNodesIn.mNumMeshes)),
|
MeshIndicies: parseUInts(cNodesIn.mMeshes, uint(cNodesIn.mNumMeshes)),
|
||||||
//TODO: Fill this
|
Metadata: parseMetadata(cNodesIn.mMetaData),
|
||||||
Metadata: &Metadata{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rn.Children = parseNodes(cNodesIn.mChildren, rn)
|
rn.Children = parseNodes(cNodesIn.mChildren, rn, uint(cNodesIn.mNumChildren))
|
||||||
return rn
|
return rn
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseNodes(cNodesIn **C.struct_aiNode, parent *Node) []*Node {
|
func parseNodes(cNodesIn **C.struct_aiNode, parent *Node, parentChildrenCount uint) []*Node {
|
||||||
|
|
||||||
if cNodesIn == nil {
|
if cNodesIn == nil {
|
||||||
return []*Node{}
|
return []*Node{}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes := make([]*Node, len(parent.Children))
|
nodes := make([]*Node, parentChildrenCount)
|
||||||
cNodes := unsafe.Slice(cNodesIn, len(parent.Children))
|
cNodes := unsafe.Slice(cNodesIn, parentChildrenCount)
|
||||||
|
|
||||||
for i := 0; i < len(nodes); i++ {
|
for i := 0; i < len(nodes); i++ {
|
||||||
|
|
||||||
@ -210,18 +215,62 @@ func parseNodes(cNodesIn **C.struct_aiNode, parent *Node) []*Node {
|
|||||||
Transformation: parseMat4(&n.mTransformation),
|
Transformation: parseMat4(&n.mTransformation),
|
||||||
Parent: parent,
|
Parent: parent,
|
||||||
MeshIndicies: parseUInts(n.mMeshes, uint(n.mNumMeshes)),
|
MeshIndicies: parseUInts(n.mMeshes, uint(n.mNumMeshes)),
|
||||||
|
Metadata: parseMetadata(n.mMetaData),
|
||||||
//TODO: Fill this
|
|
||||||
Metadata: &Metadata{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Parse node's children
|
//Parse node's children
|
||||||
nodes[i].Children = parseNodes(n.mChildren, nodes[i])
|
nodes[i].Children = parseNodes(n.mChildren, nodes[i], parentChildrenCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseMetadata(cMetaIn *C.struct_aiMetadata) map[string]Metadata {
|
||||||
|
|
||||||
|
if cMetaIn == nil {
|
||||||
|
return map[string]Metadata{}
|
||||||
|
}
|
||||||
|
|
||||||
|
meta := make(map[string]Metadata, cMetaIn.mNumProperties)
|
||||||
|
cKeys := unsafe.Slice(cMetaIn.mKeys, cMetaIn.mNumProperties)
|
||||||
|
cVals := unsafe.Slice(cMetaIn.mValues, cMetaIn.mNumProperties)
|
||||||
|
|
||||||
|
for i := 0; i < int(cMetaIn.mNumProperties); i++ {
|
||||||
|
|
||||||
|
meta[parseAiString(cKeys[i])] = parseMetadataEntry(cVals[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return meta
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseMetadataEntry(cv C.struct_aiMetadataEntry) Metadata {
|
||||||
|
|
||||||
|
m := Metadata{Type: MetadataType(cv.mType)}
|
||||||
|
|
||||||
|
if cv.mData == nil {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m.Type {
|
||||||
|
case MetadataTypeBool:
|
||||||
|
m.Value = *(*bool)(cv.mData)
|
||||||
|
case MetadataTypeFloat32:
|
||||||
|
m.Value = *(*float32)(cv.mData)
|
||||||
|
case MetadataTypeFloat64:
|
||||||
|
m.Value = *(*float64)(cv.mData)
|
||||||
|
case MetadataTypeInt32:
|
||||||
|
m.Value = *(*int32)(cv.mData)
|
||||||
|
case MetadataTypeUint64:
|
||||||
|
m.Value = *(*uint64)(cv.mData)
|
||||||
|
case MetadataTypeString:
|
||||||
|
m.Value = parseAiString(*(*C.struct_aiString)(cv.mData))
|
||||||
|
case MetadataTypeVec3:
|
||||||
|
m.Value = parseVec3((*C.struct_aiVector3D)(cv.mData))
|
||||||
|
}
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
func parseTextures(cTexIn **C.struct_aiTexture, count uint) []*EmbeddedTexture {
|
func parseTextures(cTexIn **C.struct_aiTexture, count uint) []*EmbeddedTexture {
|
||||||
|
|
||||||
if cTexIn == nil {
|
if cTexIn == nil {
|
||||||
|
|||||||
@ -315,3 +315,16 @@ func (mpti MatPropertyTypeInfo) String() string {
|
|||||||
return "Unknown"
|
return "Unknown"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MetadataType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
MetadataTypeBool MetadataType = 0
|
||||||
|
MetadataTypeInt32 MetadataType = 1
|
||||||
|
MetadataTypeUint64 MetadataType = 2
|
||||||
|
MetadataTypeFloat32 MetadataType = 3
|
||||||
|
MetadataTypeFloat64 MetadataType = 4
|
||||||
|
MetadataTypeString MetadataType = 5
|
||||||
|
MetadataTypeVec3 MetadataType = 6
|
||||||
|
MetadataTypeMAX MetadataType = 7
|
||||||
|
)
|
||||||
|
|||||||
9
main.go
9
main.go
@ -10,12 +10,13 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
scene, release, err := asig.ImportFile("tex-cube.glb", asig.PostProcessTriangulate|asig.PostProcessJoinIdenticalVertices)
|
scene, release, err := asig.ImportFile("obj2.fbx", asig.PostProcessTriangulate|asig.PostProcessJoinIdenticalVertices)
|
||||||
defer release()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
defer release()
|
||||||
|
|
||||||
|
fmt.Printf("RootNode: %+v\n\n", scene.RootNode)
|
||||||
|
|
||||||
for i := 0; i < len(scene.Meshes); i++ {
|
for i := 0; i < len(scene.Meshes); i++ {
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ func main() {
|
|||||||
for i := 0; i < len(scene.Materials); i++ {
|
for i := 0; i < len(scene.Materials); i++ {
|
||||||
|
|
||||||
m := scene.Materials[i]
|
m := scene.Materials[i]
|
||||||
println("Mesh:", i, "; Props:", len(scene.Materials[i].Properties))
|
println("Material:", i, "; Props:", len(scene.Materials[i].Properties))
|
||||||
texCount := asig.GetMaterialTextureCount(m, asig.TextureTypeDiffuse)
|
texCount := asig.GetMaterialTextureCount(m, asig.TextureTypeDiffuse)
|
||||||
fmt.Println("Texture count:", texCount)
|
fmt.Println("Texture count:", texCount)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user