Skip to content

Commit fd533bf

Browse files
committed
spx v3
1 parent adbba1f commit fd533bf

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

gsplat/read-gs-spx-v3.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,22 @@ func readSpxBF22_V3(blockBts []byte, blkSplatCnt int, header *SpxHeader, datas *
107107

108108
func readSpxBF220_WEBP_V3(blockBts []byte, blkSplatCnt int, header *SpxHeader, datas *[]*SplatData) {
109109
bts := blockBts[8:] // 除去前8字节(数量,格式)
110+
110111
size := cmn.BytesToUint32(bts[:4])
111112
webps := bts[4 : size+4]
112-
btsPositions, _, _, err := cmn.DecompressWebp(webps)
113+
btsXyz0, _, _, err := cmn.DecompressWebp(webps)
114+
cmn.ExitOnError(err)
115+
116+
bts = bts[size+4:]
117+
size = cmn.BytesToUint32(bts[:4])
118+
webps = bts[4 : size+4]
119+
btsXyz1, _, _, err := cmn.DecompressWebp(webps)
120+
cmn.ExitOnError(err)
121+
122+
bts = bts[size+4:]
123+
size = cmn.BytesToUint32(bts[:4])
124+
webps = bts[4 : size+4]
125+
btsXyz2, _, _, err := cmn.DecompressWebp(webps)
113126
cmn.ExitOnError(err)
114127

115128
bts = bts[size+4:]
@@ -141,19 +154,15 @@ func readSpxBF220_WEBP_V3(blockBts []byte, blkSplatCnt int, header *SpxHeader, d
141154
}
142155

143156
for n := range blkSplatCnt {
144-
x0 := btsPositions[n*4+0]
145-
y0 := btsPositions[n*4+1]
146-
z0 := btsPositions[n*4+2]
147-
x1 := btsPositions[blkSplatCnt*4+n*4+0]
148-
y1 := btsPositions[blkSplatCnt*4+n*4+1]
149-
z1 := btsPositions[blkSplatCnt*4+n*4+2]
150-
x2 := btsPositions[blkSplatCnt*8+n*4+0]
151-
y2 := btsPositions[blkSplatCnt*8+n*4+1]
152-
z2 := btsPositions[blkSplatCnt*8+n*4+2]
153-
rx := btsRotations[n*4+0]
154-
ry := btsRotations[n*4+1]
155-
rz := btsRotations[n*4+2]
156-
ri := btsRotations[n*4+3]
157+
x0 := btsXyz0[n*4+0]
158+
y0 := btsXyz0[n*4+1]
159+
z0 := btsXyz0[n*4+2]
160+
x1 := btsXyz1[n*4+0]
161+
y1 := btsXyz1[n*4+1]
162+
z1 := btsXyz1[n*4+2]
163+
x2 := btsXyz2[n*4+0]
164+
y2 := btsXyz2[n*4+1]
165+
z2 := btsXyz2[n*4+2]
157166

158167
data := &SplatData{}
159168
data.PositionX = cmn.DecodeLog(cmn.DecodeSpxPositionUint24(x0, x1, x2), 1)
@@ -166,6 +175,10 @@ func readSpxBF220_WEBP_V3(blockBts []byte, blkSplatCnt int, header *SpxHeader, d
166175
data.ColorG = btsColors[n*4+1]
167176
data.ColorB = btsColors[n*4+2]
168177
data.ColorA = btsColors[n*4+3]
178+
rx := btsRotations[n*4+0]
179+
ry := btsRotations[n*4+1]
180+
rz := btsRotations[n*4+2]
181+
ri := btsRotations[n*4+3]
169182
data.RotationW, data.RotationX, data.RotationY, data.RotationZ = cmn.SogDecodeRotations(rx, ry, rz, ri)
170183

171184
if len(btsPaletteIdxs) > 0 {

gsplat/write-gs-spx-v3.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ func writeSpxBF220_WEBP_V3(writer *bufio.Writer, blockDatas []*SplatData, shDegr
313313
bts = append(bts, cmn.Uint32ToBytes(uint32(len(blockDatas)))...) // 块中的高斯点个数
314314
bts = append(bts, cmn.Uint32ToBytes(BF_SPLAT220_WEBP)...) // 开放的块数据格式 220
315315

316-
bsTmp := make([]byte, 0)
317316
bs1 := make([]byte, 0)
318317
bs2 := make([]byte, 0)
319318
bs3 := make([]byte, 0)
@@ -325,10 +324,17 @@ func writeSpxBF220_WEBP_V3(writer *bufio.Writer, blockDatas []*SplatData, shDegr
325324
bs2 = append(bs2, b3x[1], b3y[1], b3z[1], 255)
326325
bs3 = append(bs3, b3x[2], b3y[2], b3z[2], 255)
327326
}
328-
bsTmp = append(bsTmp, bs1...)
329-
bsTmp = append(bsTmp, bs2...)
330-
bsTmp = append(bsTmp, bs3...)
331-
bsTmp, err := cmn.CompressWebp(bsTmp)
327+
bsTmp, err := cmn.CompressWebp(bs1)
328+
cmn.ExitOnError(err)
329+
bts = append(bts, cmn.Uint32ToBytes(uint32(len(bsTmp)))...)
330+
bts = append(bts, bsTmp...)
331+
332+
bsTmp, err = cmn.CompressWebp(bs2)
333+
cmn.ExitOnError(err)
334+
bts = append(bts, cmn.Uint32ToBytes(uint32(len(bsTmp)))...)
335+
bts = append(bts, bsTmp...)
336+
337+
bsTmp, err = cmn.CompressWebp(bs3)
332338
cmn.ExitOnError(err)
333339
bts = append(bts, cmn.Uint32ToBytes(uint32(len(bsTmp)))...)
334340
bts = append(bts, bsTmp...)

0 commit comments

Comments
 (0)