-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextureAtlas.go
175 lines (139 loc) · 4.12 KB
/
TextureAtlas.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
package bone
import (
wrapper "dragonBones/dragonBones"
"image"
_ "image/png"
"log"
"os"
"github.com/EngoEngine/engo"
"github.com/EngoEngine/engo/common"
)
type TextureAtlasDataFace interface {
wrapper.TextureAtlasData
deleteTextureAtlas()
IsTextureAtlas()
}
type DragonBonesData struct {
wrapper.DragonBonesData
binary *string
}
func NewDragonBonesData(data wrapper.DragonBonesData, binary *string) *DragonBonesData {
dragonBonesData := &DragonBonesData{DragonBonesData: data}
if len(*binary) > 4 &&
(*binary)[0] == 'D' ||
(*binary)[1] == 'B' ||
(*binary)[2] == 'D' ||
(*binary)[3] == 'T' {
dragonBonesData.binary = binary
}
boneObjectAdd(data.Swigcptr(), dragonBonesData)
return dragonBonesData
}
type TextureAtlasDataImpl struct {
wrapper.TextureAtlasData
TextureResource *common.TextureResource
}
func (tex *TextureAtlasDataImpl) IsTextureAtlas() {}
func (tex *TextureAtlasDataImpl) deleteTextureAtlas() {
wrapper.DeleteDirectorTextureAtlasData(tex.TextureAtlasData)
}
func (tex *TextureAtlasDataImpl) setRenderTexture(texture *common.TextureResource) {
if tex.TextureResource == texture {
return
}
tex.TextureResource = texture
if tex.TextureResource == nil {
textures := tex.GetTextures().Values()
for i := 0; i < int(textures.Size()); i++ {
texture := textures.Get(i)
textureImpl := boneObjectLookup(texture.Swigcptr()).(*TextureDataImpl)
textureImpl.TextureResource = nil
}
} else {
textures := tex.GetTextures().Values()
for i := 0; i < int(textures.Size()); i++ {
texture := textures.Get(i)
region := texture.GetRegion()
rotated := texture.GetRotated()
x, y, width, height := region.GetX(), region.GetY(), region.GetWidth(), region.GetHeight()
textureImpl := boneObjectLookup(texture.Swigcptr()).(*TextureDataImpl)
if rotated {
width, height = height, width
}
log.Println("SubTextureRegion")
viewport := engo.AABB{
Min: engo.Point{
X: x / tex.TextureResource.Width,
Y: y / tex.TextureResource.Height,
},
Max: engo.Point{
X: (x + width) / tex.TextureResource.Width,
Y: (y + height) / tex.TextureResource.Height,
},
}
textureImpl.Rotated = rotated
textureImpl.Parent = tex
textureImpl.TextureResource = &common.TextureResource{Texture: tex.TextureResource.Texture, Width: width, Height: height, Viewport: &viewport}
}
}
}
func NewTextureAtlasData() *TextureAtlasDataImpl {
om := &overwrittenMethodsOnTextureAtlasData{}
face := wrapper.NewDirectorTextureAtlasData(om)
wrapper.DirectorTextureAtlasDataX_onClear(face)
om.base = face
data := &TextureAtlasDataImpl{TextureAtlasData: face}
boneObjectAdd(data.Swigcptr(), data)
return data
}
type overwrittenMethodsOnTextureAtlasData struct {
base wrapper.TextureAtlasData
}
func (om *overwrittenMethodsOnTextureAtlasData) GetClassTypeIndex() int64 {
return wrapper.GetTextureAtlasDataTypeIndex(om.base)
}
func (om *overwrittenMethodsOnTextureAtlasData) CreateTexture() wrapper.TextureData {
return NewTextureData()
}
type TextureDataFace interface {
wrapper.TextureData
deleteTextureData()
IsTextureData()
}
type TextureDataImpl struct {
wrapper.TextureData
TextureResource *common.TextureResource
Parent *TextureAtlasDataImpl
Rotated bool
}
func (tex *TextureDataImpl) IsTextureData() {}
func (tex *TextureDataImpl) deleteTextureData() {
wrapper.DeleteDirectorTextureData(tex.TextureData)
}
func NewTextureData() *TextureDataImpl {
om := &overwrittenMethodsOnTextureData{}
face := wrapper.NewDirectorTextureData(om)
om.base = face
data := &TextureDataImpl{TextureData: face}
boneObjectAdd(data.Swigcptr(), data)
return data
}
func LoadTextureAtlas(imagePath string) (*common.TextureResource, error) {
// todo
log.Println("LoadTextureAtlas", imagePath)
f, err := os.Open(imagePath)
if err != nil {
return nil, err
}
img, _, err := image.Decode(f)
if err != nil {
return nil, err
}
bounds := img.Bounds()
imageObject := common.NewImageObject(common.ImageToNRGBA(img, bounds.Dx(), bounds.Dy()))
texture := common.NewTextureResource(imageObject)
return &texture, nil
}
type overwrittenMethodsOnTextureData struct {
base wrapper.TextureData
}