Skip to content

Commit d3b9596

Browse files
author
hj
committed
update
1 parent 08292dc commit d3b9596

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

dataview.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func BufferDataView(buff *bytes.Buffer) *DataView {
2727
}
2828

2929
func (dv *DataView) String() string {
30+
dv.Seek(0, io.SeekStart)
3031
ln := dv.Len()
3132
data := make([]byte, ln)
3233
_, err := dv.Read(data)
@@ -40,6 +41,8 @@ func (dv *DataView) String() string {
4041

4142
func (dv *DataView) touint64() uint64 {
4243
var i uint64
44+
dv.Seek(0, io.SeekStart)
45+
4346
err := binary.Read(dv, binary.LittleEndian, &i)
4447
if err != nil && err != io.EOF {
4548
fmt.Println("binary read failure:", err)
@@ -49,6 +52,7 @@ func (dv *DataView) touint64() uint64 {
4952

5053
func (dv *DataView) toint64() int64 {
5154
var i int64
55+
dv.Seek(0, io.SeekStart)
5256
err := binary.Read(dv, binary.LittleEndian, &i)
5357
if err != nil && err != io.EOF {
5458
fmt.Println("binary read failure:", err)
@@ -58,6 +62,7 @@ func (dv *DataView) toint64() int64 {
5862

5963
func (dv *DataView) toInt32() int32 {
6064
var i int32
65+
dv.Seek(0, io.SeekStart)
6166
err := binary.Read(dv, binary.LittleEndian, &i)
6267
if err != nil && err != io.EOF {
6368
fmt.Println("binary read failure:", err)
@@ -67,6 +72,7 @@ func (dv *DataView) toInt32() int32 {
6772

6873
func (dv *DataView) touint32() uint32 {
6974
var i uint32
75+
dv.Seek(0, io.SeekStart)
7076
err := binary.Read(dv, binary.LittleEndian, &i)
7177
if err != nil && err != io.EOF {
7278
fmt.Println("binary read failure:", err)
@@ -76,6 +82,7 @@ func (dv *DataView) touint32() uint32 {
7682

7783
func (dv *DataView) toDouble() float64 {
7884
var i float64
85+
dv.Seek(0, io.SeekStart)
7986
err := binary.Read(dv, binary.LittleEndian, &i)
8087
if err != nil && err != io.EOF {
8188
fmt.Println("binary read failure:", err)
@@ -85,6 +92,7 @@ func (dv *DataView) toDouble() float64 {
8592

8693
func (dv *DataView) toFloat() float32 {
8794
var i float32
95+
dv.Seek(0, io.SeekStart)
8896
err := binary.Read(dv, binary.LittleEndian, &i)
8997
if err != nil && err != io.EOF {
9098
fmt.Println("binary read failure:", err)
@@ -94,6 +102,7 @@ func (dv *DataView) toFloat() float32 {
94102

95103
func (dv *DataView) toBool() bool {
96104
var i bool
105+
dv.Seek(0, io.SeekStart)
97106
err := binary.Read(dv, binary.LittleEndian, &i)
98107
if err != nil && err != io.EOF {
99108
fmt.Println("binary read failure:", err)

geometry.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var vtxDataMapFromStrs = map[string]VertexDataMapping{
2727
// MaxUvs is the highest number of UVs allowed
2828
const MaxUvs = 4
2929

30-
//Geometry is the base geometric shape objec that is implemented in forms such as meshes that dictate control point deformations
30+
// Geometry is the base geometric shape objec that is implemented in forms such as meshes that dictate control point deformations
3131
type Geometry struct {
3232
Object
3333
Skin *Skin
@@ -333,7 +333,6 @@ func parseGeometry(scene *Scene, element *Element) (*Geometry, error) {
333333
if tmp != nil && len(tmp) > 0 {
334334
//uvs = [4]floatgeom.Point2{} //resize(tmpIndices.empty() ? tmp.size() : tmpIndices.size());
335335
geom.UVs[uvIdx] = splatVec2(mapping, tmp, tmpIndices, origIndices)
336-
remapVec2(&geom.UVs[uvIdx], toOldIndices)
337336
}
338337
}
339338

@@ -368,7 +367,6 @@ func parseGeometry(scene *Scene, element *Element) (*Geometry, error) {
368367
}
369368
if len(tmp) > 0 {
370369
geom.Colors = splatVec4(mapping, tmp, tmpIndices, origIndices)
371-
remapVec4(&geom.Colors, toOldIndices)
372370
}
373371
}
374372

@@ -380,7 +378,6 @@ func parseGeometry(scene *Scene, element *Element) (*Geometry, error) {
380378
}
381379
if len(tmp) > 0 {
382380
geom.Normals = splatVec3(mapping, tmp, tmpIndices, origIndices)
383-
remapVec3(&geom.Normals, toOldIndices)
384381
}
385382
}
386383

mesh.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package ofbx
22

33
import (
44
"fmt"
5-
6-
"github.com/oakmound/oak/v2/alg/floatgeom"
75
)
86

97
// Mesh is a geometry made of polygon
@@ -56,10 +54,10 @@ func (m *Mesh) Type() Type {
5654
return MESH
5755
}
5856

59-
func (m *Mesh) getGeometricMatrix() Matrix {
60-
translation := resolveVec3Property(m, "GeometricTranslation", floatgeom.Point3{0, 0, 0})
61-
rotation := resolveVec3Property(m, "GeometricRotation", floatgeom.Point3{0, 0, 0})
62-
scale := resolveVec3Property(m, "GeometricScaling", floatgeom.Point3{1, 1, 1})
57+
func (m *Mesh) GetGeometricMatrix() Matrix {
58+
translation := getLocalTranslation(m)
59+
rotation := getLocalRotation(m)
60+
scale := getLocalScaling(m)
6361

6462
scaleMtx := makeIdentity()
6563
scaleMtx.m[0] = scale.X()

object.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,13 @@ func getLocalScaling(o Obj) floatgeom.Point3 {
221221

222222
func getGlobalTransform(o Obj) Matrix {
223223
parent := getParent(o)
224+
lmt := evalLocal(o, getLocalTranslation(o), getLocalRotation(o))
224225
if parent == nil {
225-
return evalLocal(o, getLocalTranslation(o), getLocalRotation(o))
226+
return lmt
226227
}
228+
mt := getGlobalTransform(parent)
227229

228-
return getGlobalTransform(parent).Mul(evalLocal(o, getLocalTranslation(o), getLocalRotation(o)))
230+
return mt.Mul(lmt)
229231
}
230232

231233
func getLocalTransform(o Obj) Matrix {

print_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,29 @@ func TestPrintScene(t *testing.T) {
1919
fmt.Println(scene)
2020
fmt.Println(scene.Meshes[0].Materials[0].Textures[0].relativeFilename)
2121
}
22+
23+
func TestMatrix(t *testing.T) {
24+
f, err := os.Open("/home/hj/snap/dukto/16/md/AOI.fbx")
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
scene, err := Load(f)
29+
if err != nil {
30+
log.Fatal(err)
31+
}
32+
33+
mt := getGlobalTransform(scene.ObjectMap[2281135157232])
34+
fmt.Println(mt)
35+
mt2 := getGlobalTransform(scene.ObjectMap[2281135157232])
36+
fmt.Println(mt2)
37+
38+
for _, m := range scene.Meshes[12:] {
39+
// mt := getLocalTransform(m)
40+
// fmt.Println(mt)
41+
42+
mt2 := getGlobalTransform(m)
43+
fmt.Println(mt2)
44+
45+
}
46+
47+
}

texture.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ofbx
22

3-
//TextureType determines how a texture be used
3+
// TextureType determines how a texture be used
44
type TextureType int
55

66
// Texture type block
@@ -10,7 +10,7 @@ const (
1010
TextureCOUNT TextureType = iota
1111
)
1212

13-
//Texture is a texture file on an object
13+
// Texture is a texture file on an object
1414
type Texture struct {
1515
Object
1616
filename *DataView
@@ -42,6 +42,10 @@ func (t *Texture) getRelativeFileName() *DataView {
4242
return t.relativeFilename
4343
}
4444

45+
func (t *Texture) GetRelativeFileName() *DataView {
46+
return t.relativeFilename
47+
}
48+
4549
func (t *Texture) String() string {
4650
s := "Texture: " + t.Object.String()
4751
s += ", filename: " + t.filename.String()

0 commit comments

Comments
 (0)