Handle (embedded)textures

This commit is contained in:
bloeys
2021-11-19 21:05:21 +04:00
parent 3b31e8d677
commit 4462a3be04
5 changed files with 163 additions and 27 deletions

View File

@ -24,6 +24,10 @@ enum aiReturn aiGetMaterialTexture(
unsigned int* flags);
*/
import "C"
import (
"errors"
"fmt"
)
type Material struct {
cMat *C.struct_aiMaterial
@ -59,12 +63,35 @@ type MaterialProperty struct {
*/
TypeInfo MatPropertyTypeInfo
/** Binary buffer to hold the property's value.
* The size of the buffer is always mDataLength.
*/
//Binary buffer to hold the property's value.
Data []byte
}
func GetMaterialTextureCount(m *Material, texType TextureType) int {
return int(C.aiGetMaterialTextureCount(m.cMat, uint32(texType)))
}
type GetMatTexInfo struct {
Path string
}
func GetMaterialTexture(m *Material, texType TextureType, texIndex uint) (*GetMatTexInfo, error) {
outCPath := &C.struct_aiString{}
status := aiReturn(C.aiGetMaterialTexture(m.cMat, uint32(texType), C.uint(texIndex), outCPath, nil, nil, nil, nil, nil, nil))
if status == aiReturnSuccess {
return &GetMatTexInfo{
Path: parseAiString(*outCPath),
}, nil
}
if status == aiReturnFailure {
return nil, errors.New("get texture failed: " + getAiErr().Error())
}
if status == aiReturnOutofMemory {
return nil, errors.New("get texture failed: out of memory")
}
return nil, errors.New("get texture failed: unknown error with code " + fmt.Sprintf("%v", status))
}