forked from cubzh/cubzh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcubzh-file-format-3zh.txt
240 lines (182 loc) · 9.1 KB
/
cubzh-file-format-3zh.txt
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
Cubzh .3zh File Format [10/20/2022]
File
{
Header
// PNG Preview
Chunk 'PREVIEW' : optional
// Palette
Chunk 'PALETTE' : optional
// Objects
Chunk 'SHAPE' / Chunk 'OBJECT' : optional
...
Chunk 'SHAPE' / Chunk 'OBJECT' : optional
}
-------------------------------------------------------------------------------
1. Header
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
6 | char | magic bytes 'CUBZH!' : 'C' 'U' 'B' 'Z' 'H' '!', 'C' is first
4 | int | version number : 6
1 | uint8 | compression method : 0 (none), 1 (zip)
4 | uint32 | total size of data (compressed or not)
2. Chunk Structure (not SubChunks)
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | uint8 | chunk id
4 | uint32 | num bytes of chunk content (N)
1 | uint8 | (0: not compressed - 1: compressed)
4 | uint32 | num bytes of chunk content uncompressed (M)
N or M | | chunk content
-------------------------------------------------------------------------------
3. Chunk id 'PREVIEW' (1) : if it is absent, no PNG preview available
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
N | | PNG bytes
-------------------------------------------------------------------------------
4. Chunk id 'PALETTE' : optional, contains colors. Not related to any shapes
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | uint8 | color count (N)
N x 4 | uint8 | (r, g, b, alpha) : 1 byte for each entry
N | uint8 | emissive flag
-------------------------------------------------------------------------------
5. Chunk id 'OBJECT'
{
SubChunk 'OBJECT_ID' : optional (default 1)
SubChunk 'OBJECT_PARENT' : optional
SubChunk 'OBJECT_TRANSFORM' : optional
SubChunk 'OBJECT_PIVOT' : optional
}
6. Chunk id 'SHAPE' (3)
{
SubChunk 'OBJECT_ID' : optional (default 1)
SubChunk 'OBJECT_NAME' : optional
SubChunk 'OBJECT_PARENT' : optional
SubChunk 'OBJECT_TRANSFORM' : optional
SubChunk 'OBJECT_PIVOT' : optional
SubChunk 'OBJECT_COLLISION_BOX' : optional
SubChunk 'OBJECT_IS_HIDDEN' : optional
SubChunk 'SHAPE_PALETTE' : optional
SubChunk 'SHAPE_SIZE'
SubChunk 'SHAPE_BLOCKS'
SubChunk 'SHAPE_POINT' : optional, multiple (named point)
SubChunk 'SHAPE_POINT_ROTATION' : optional, multiple (named rotation)
SubChunk 'SHAPE_BAKED_LIGHTING' : optional
}
7. Subchunk structure
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | byte | chunk id
4 | uint32 | chunk size
-------------------------------------------------------------------------------
8. SubChunk id 'OBJECT_ID' (18) : only for serialization in parent id
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
2 | uint16 | id
-------------------------------------------------------------------------------
9. SubChunk id 'OBJECT_NAME' (17) : only for serialization in parent id
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | uint8 | lenName (N)
N | string | name
-------------------------------------------------------------------------------
10. SubChunk id 'OBJECT_PARENT' (19) : based on chunk 'OBJECT_ID'
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
2 | uint16 | id
-------------------------------------------------------------------------------
11. SubChunk id 'OBJECT_TRANSFORM' (20) : local transform, only if chunk 'OBJECT_PARENT' defined
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
4 | float | position x
4 | float | position y
4 | float | position z
4 | float | rotation x
4 | float | rotation y
4 | float | rotation z
4 | float | scale x
4 | float | scale y
4 | float | scale z
-------------------------------------------------------------------------------
12. SubChunk id 'OBJECT_PIVOT' (21) : optional, default center of shape
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
4 | float | position x
4 | float | position y
4 | float | position z
-------------------------------------------------------------------------------
13. SubChunk id 'OBJECT_COLLISION_BOX' (23) : optional, default is a box containing the whole shape
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
4 | float | position min x
4 | float | position min y
4 | float | position min z
4 | float | position max x
4 | float | position max y
4 | float | position max z
-------------------------------------------------------------------------------
14. SubChunk id 'OBJECT_IS_HIDDEN' (24) : optional, visible by default
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | uint8 | 0 if visible, 1 if hidden
-------------------------------------------------------------------------------
15. SubChunk id 'SHAPE_SIZE' (4)
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
2 | short | width (x)
2 | short | height (y)
2 | short | depth (z)
-------------------------------------------------------------------------------
16. SubChunk id 'SHAPE_BLOCKS' (5)
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
C * 1 | uint8 | palette index (255 if air block) (C is blockCount)
-------------------------------------------------------------------------------
17. SubChunk id 'SHAPE_POINT' (6)
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | uint8 | name length (N)
N * 1 | string | name
4 | float | position x
4 | float | position y
4 | float | position z
-------------------------------------------------------------------------------
18. SubChunk id 'SHAPE_POINT_ROTATION' (8)
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | uint8 | name length (N)
N * 1 | string | name
4 | float | rotation x
4 | float | rotation y
4 | float | rotation z
-------------------------------------------------------------------------------
19. SubChunk id 'SHAPE_BAKED_LIGHTING' (7)
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
C * 2 | uint8 | light : 2 bytes per block (C is blockCount)
-------------------------------------------------------------------------------
20. SubChunk id 'SHAPE_PALETTE' (22) : optional, contains the colors of the shape
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
1 | uint8 | color count (N)
N x 4 | uint8 | (r, g, b, alpha) : 1 byte for each entry
N | uint8 | emissive flag
-------------------------------------------------------------------------------