forked from krux02/assimp
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Material.go
281 lines (232 loc) · 9.93 KB
/
Material.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package assimp
/*
#cgo pkg-config: assimp
#include <assimp/material.h>
#include <stdlib.h>
*/
import "C"
import (
"reflect"
"unsafe"
)
type TextureOp C.enum_aiTextureOp
const (
TextureOp_Multiply TextureOp = C.aiTextureOp_Multiply
TextureOp_Add TextureOp = C.aiTextureOp_Add
TextureOp_Subtract TextureOp = C.aiTextureOp_Subtract
TextureOp_Divide TextureOp = C.aiTextureOp_Divide
TextureOp_SmoothAdd TextureOp = C.aiTextureOp_SmoothAdd
TextureOp_SignedAdd TextureOp = C.aiTextureOp_SignedAdd
)
type TextureMapMode C.enum_aiTextureMapMode
const (
TextureMapMode_Wrap TextureMapMode = C.aiTextureMapMode_Wrap
TextureMapMode_Clamp TextureMapMode = C.aiTextureMapMode_Clamp
TextureMapMode_Decal TextureMapMode = C.aiTextureMapMode_Decal
TextureMapMode_Mirror TextureMapMode = C.aiTextureMapMode_Mirror
)
type TextureMapping C.enum_aiTextureMapping
const (
TextureMapping_Uv TextureMapping = C.aiTextureMapping_UV
TextureMapping_Spere TextureMapping = C.aiTextureMapping_SPHERE
TextureMapping_Cylinder TextureMapping = C.aiTextureMapping_CYLINDER
TextureMapping_Box TextureMapping = C.aiTextureMapping_BOX
TextureMapping_Plane TextureMapping = C.aiTextureMapping_PLANE
TextureMapping_Other TextureMapping = C.aiTextureMapping_OTHER
)
type TextureType C.enum_aiTextureType
const (
TextureMapping_None TextureMapping = C.aiTextureType_NONE
TextureMapping_Diffuse TextureMapping = C.aiTextureType_DIFFUSE
TextureMapping_Specular TextureMapping = C.aiTextureType_SPECULAR
TextureMapping_Ambient TextureMapping = C.aiTextureType_AMBIENT
TextureMapping_Emissive TextureMapping = C.aiTextureType_EMISSIVE
TextureMapping_Height TextureMapping = C.aiTextureType_HEIGHT
TextureMapping_Normals TextureMapping = C.aiTextureType_NORMALS
TextureMapping_Shininess TextureMapping = C.aiTextureType_SHININESS
TextureMapping_Opacity TextureMapping = C.aiTextureType_OPACITY
TextureMapping_Displacement TextureMapping = C.aiTextureType_DISPLACEMENT
TextureMapping_Lightmap TextureMapping = C.aiTextureType_LIGHTMAP
TextureMapping_Reflection TextureMapping = C.aiTextureType_REFLECTION
TextureMapping_Unknown TextureMapping = C.aiTextureType_UNKNOWN
)
const TextureTypeMax = C.AI_TEXTURE_TYPE_MAX
type ShadingMode C.enum_aiShadingMode
const (
ShadingMode_Flat ShadingMode = C.aiShadingMode_Flat
ShadingMode_Gouraud ShadingMode = C.aiShadingMode_Gouraud
ShadingMode_Phong ShadingMode = C.aiShadingMode_Phong
ShadingMode_Blinn ShadingMode = C.aiShadingMode_Blinn
ShadingMode_Tonn ShadingMode = C.aiShadingMode_Toon
ShadingMode_OrenNayar ShadingMode = C.aiShadingMode_OrenNayar
ShadingMode_Minnaert ShadingMode = C.aiShadingMode_Minnaert
ShadingMode_CookTorrance ShadingMode = C.aiShadingMode_CookTorrance
ShadingMode_NoShading ShadingMode = C.aiShadingMode_NoShading
ShadingMode_Fresnel ShadingMode = C.aiShadingMode_Fresnel
)
type TextureFlags C.enum_aiTextureFlags
const (
TextureFlags_Invert TextureFlags = C.aiTextureFlags_Invert
TextureFlags_UseAlpha TextureFlags = C.aiTextureFlags_UseAlpha
TextureFlags_IgnoreAlpha TextureFlags = C.aiTextureFlags_IgnoreAlpha
)
type BlendMode C.enum_aiBlendMode
const (
BlendMode_Default BlendMode = C.aiBlendMode_Default
BlendMode_Additive BlendMode = C.aiBlendMode_Additive
)
type UvTransform C.struct_aiUVTransform
func (tf UvTransform) Translation() Vector2 {
return Vector2(tf.mTranslation)
}
func (tf UvTransform) Scaling() Vector2 {
return Vector2(tf.mScaling)
}
func (tf UvTransform) Rotation() float32 {
return float32(tf.mRotation)
}
type PropertyTypeInfo C.enum_aiPropertyTypeInfo
const (
PTI_Float PropertyTypeInfo = C.aiPTI_Float
PTI_String PropertyTypeInfo = C.aiPTI_String
PTI_Integer PropertyTypeInfo = C.aiPTI_Integer
PTI_Buffer PropertyTypeInfo = C.aiPTI_Buffer
)
type MaterialProperty C.struct_aiMaterialProperty
func (mp *MaterialProperty) Key() string {
return C.GoStringN(&mp.mKey.data[0], C.int(mp.mKey.length))
}
func (mp *MaterialProperty) Semantic() int {
return int(mp.mSemantic)
}
func (mp *MaterialProperty) Index() int {
return int(mp.mIndex)
}
func (mp *MaterialProperty) DataLength() int {
return int(mp.mDataLength)
}
func (mp *MaterialProperty) Type() PropertyTypeInfo {
return PropertyTypeInfo(mp.mType)
}
func (mp *MaterialProperty) Data() []byte {
if mp.mData != nil {
var result []byte
header := (*reflect.SliceHeader)(unsafe.Pointer(&result))
header.Cap = int(mp.mDataLength)
header.Len = int(mp.mDataLength)
header.Data = uintptr(unsafe.Pointer(mp.mData))
return result
} else {
return nil
}
}
type Material C.struct_aiMaterial
func (m *Material) NumProperties() int {
return int(m.mNumProperties)
}
func (m *Material) NumAllocated() int {
return int(m.mNumAllocated)
}
func (m *Material) Properties() []MaterialProperty {
if m.mProperties != nil {
var result []MaterialProperty
header := (*reflect.SliceHeader)(unsafe.Pointer(&result))
header.Cap = int(m.mNumProperties)
header.Len = int(m.mNumProperties)
header.Data = uintptr(unsafe.Pointer(m.mProperties))
return result
} else {
return nil
}
}
type MatKey string
const (
MatKey_Name MatKey = "?mat.name"
MatKey_TwoSidid MatKey = "$mat.twosided"
MatKey_ShadingModel MatKey = "$mat.shadingm"
MatKey_EnableWireframe MatKey = "$mat.wireframe"
MatKey_BlendFunc MatKey = "$mat.blend"
MatKey_Opacity MatKey = "$mat.opacity"
MatKey_BumpScaling MatKey = "$mat.bumpscaling"
MatKey_Shininess MatKey = "$mat.shininess"
MatKey_Reflectivity MatKey = "$mat.reflectivity"
MatKey_ShininessStregth MatKey = "$mat.shinpercent"
MatKey_Refracti MatKey = "$mat.refracti"
MatKey_ColorDiffuse MatKey = "$clr.diffuse"
MatKey_ColorAmbient MatKey = "$clr.ambient"
MatKey_ColorSpecular MatKey = "$clr.specular"
MatKey_ColorEmissive MatKey = "$clr.emissive"
MatKey_ColorTransparent MatKey = "$clr.transparent"
MatKey_ColorReflective MatKey = "$clr.reflective"
MatKey_GlobalBackgroundImage MatKey = "?bg.global"
)
const (
MatKey_Texture MatKey = C._AI_MATKEY_TEXTURE_BASE
MatKey_UvwSrc MatKey = C._AI_MATKEY_UVWSRC_BASE
MatKey_TexOp MatKey = C._AI_MATKEY_TEXOP_BASE
MatKey_Mapping MatKey = C._AI_MATKEY_MAPPING_BASE
MatKey_TexBlend MatKey = C._AI_MATKEY_TEXBLEND_BASE
MatKey_MappingModeU MatKey = C._AI_MATKEY_MAPPINGMODE_U_BASE
MatKey_MappingModeV MatKey = C._AI_MATKEY_MAPPINGMODE_V_BASE
MatKey_TexMapAxis MatKey = C._AI_MATKEY_TEXMAP_AXIS_BASE
MatKey_UvTransform MatKey = C._AI_MATKEY_UVTRANSFORM_BASE
MatKey_TexFlags MatKey = C._AI_MATKEY_TEXFLAGS_BASE
)
func (mk MatKey) constString() *C.char {
header := (*reflect.StringHeader)(unsafe.Pointer(&mk))
return (*C.char)(unsafe.Pointer(header.Data))
}
func (m *Material) GetMaterialProperty(key MatKey, typ TextureType, textureIndex int) (*MaterialProperty, Return) {
pKey := key.constString()
var pPropOut *C.struct_aiMaterialProperty
ret := C.aiGetMaterialProperty((*C.struct_aiMaterial)(m), pKey, C.uint(typ), C.uint(textureIndex), &pPropOut)
return (*MaterialProperty)(pPropOut), Return(ret)
}
func (m *Material) GetMaterialFloatArray(key MatKey, typ TextureType, textureIndex int, pOut []float32) Return {
header := (*reflect.SliceHeader)(unsafe.Pointer(&pOut))
ret := C.aiGetMaterialFloatArray((*C.struct_aiMaterial)(m), key.constString(), C.uint(typ), C.uint(textureIndex), (*C.ai_real)(&pOut[0]), (*C.uint)(unsafe.Pointer((&header.Len))))
return Return(ret)
}
func (m *Material) GetMaterialFloat(key MatKey, typ TextureType, textureIndex int) (float32, Return) {
var f float32
ret := C.aiGetMaterialFloatArray((*C.struct_aiMaterial)(m), key.constString(), C.uint(typ), C.uint(textureIndex), (*C.ai_real)(&f), nil)
return f, Return(ret)
}
func (m *Material) GetMaterialInteger(key MatKey, typ TextureType, textureIndex int) (int, Return) {
var i C.int
ret := C.aiGetMaterialIntegerArray((*C.struct_aiMaterial)(m), key.constString(), C.uint(typ), C.uint(textureIndex), &i, nil)
return int(i), Return(ret)
}
func (m *Material) GetMaterialIntegerArray(key MatKey, typ TextureType, textureIndex int, pOut []int32) Return {
header := (*reflect.SliceHeader)(unsafe.Pointer(&pOut))
ret := C.aiGetMaterialIntegerArray((*C.struct_aiMaterial)(m), key.constString(), C.uint(typ), C.uint(textureIndex), (*C.int)(&pOut[0]), (*C.uint)(unsafe.Pointer((&header.Len))))
return Return(ret)
}
func (m *Material) GetMaterialColor(key MatKey, typ TextureType, textureIndex int) (Color4, Return) {
var color C.struct_aiColor4D
ret := C.aiGetMaterialColor((*C.struct_aiMaterial)(m), key.constString(), C.uint(typ), C.uint(textureIndex), &color)
return Color4(color), Return(ret)
}
func (m *Material) GetMaterialString(key MatKey, typ TextureType, textureIndex int) (string, Return) {
var str C.struct_aiString
ret := C.aiGetMaterialString((*C.struct_aiMaterial)(m), key.constString(), C.uint(typ), C.uint(textureIndex), &str)
return C.GoString(&str.data[0]), Return(ret)
}
func (m *Material) GetMaterialTextureCount(typ TextureType) int {
ret := C.aiGetMaterialTextureCount((*C.struct_aiMaterial)(m), C.enum_aiTextureType(typ))
return int(ret)
}
func (m *Material) GetMaterialTexture(typ TextureType, textureIndex int) (string, TextureMapping, int, float32, TextureOp, TextureMapMode, uint, Return) {
var mat *C.struct_aiMaterial = (*C.struct_aiMaterial)(m)
var typ_ C.enum_aiTextureType = C.enum_aiTextureType(typ)
var index C.uint = C.uint(textureIndex)
var path C.struct_aiString
var mapping C.enum_aiTextureMapping
var uvindex C.uint
var blend C.ai_real
var op C.enum_aiTextureOp
var mapmode C.enum_aiTextureMapMode
var flags C.uint
ret := C.aiGetMaterialTexture(mat, typ_, index, &path, &mapping, &uvindex, &blend, &op, &mapmode, &flags)
return C.GoString(&path.data[0]), TextureMapping(mapping), int(uvindex), float32(blend), TextureOp(op), TextureMapMode(mapmode), uint(flags), Return(ret)
}