MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / copyShCoeff

Function copyShCoeff

CesiumGltfReader/src/decodeSpz.cpp:112–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112void copyShCoeff(
113 GltfReaderResult& readGltf,
114 CesiumGltf::MeshPrimitive& primitive,
115 CesiumGltf::Buffer& buffer,
116 const spz::GaussianCloud& gaussian,
117 int degree,
118 int coeffIndex) {
119 size_t base = 0;
120 size_t stride = 0;
121 if (degree == 1) {
122 stride = 9;
123 } else if (degree == 2) {
124 stride = 24;
125 base = 9;
126 } else if (degree == 3) {
127 stride = 45;
128 base = 24;
129 }
130
131 CesiumGltf::Accessor* pAccessor = findAccessor(
132 readGltf,
133 primitive,
134 fmt::format(
135 "KHR_gaussian_splatting:SH_DEGREE_{}_COEF_{}",
136 degree,
137 coeffIndex));
138 if (!pAccessor) {
139 return;
140 }
141
142 CESIUM_ASSERT(readGltf.model);
143
144 // Some gaussian splats seem to set this value as VEC4, even though the spec
145 // requires VEC3.
146 pAccessor->type = CesiumGltf::Accessor::Type::VEC3;
147
148 pAccessor->bufferView =
149 static_cast<int32_t>(readGltf.model->bufferViews.size());
150 CesiumGltf::BufferView& bufferView =
151 readGltf.model->bufferViews.emplace_back();
152 bufferView.buffer = static_cast<int32_t>(readGltf.model->buffers.size() - 1);
153 bufferView.byteLength = static_cast<int64_t>(
154 sizeof(float) * static_cast<size_t>(gaussian.numPoints) * 3);
155
156 size_t start = buffer.cesium.data.size();
157 bufferView.byteOffset = static_cast<int64_t>(start);
158 buffer.cesium.data.resize(start + static_cast<size_t>(bufferView.byteLength));
159 for (size_t i = 0; i < static_cast<size_t>(gaussian.numPoints); i++) {
160 const size_t idx = i * stride + base + static_cast<size_t>(coeffIndex) * 3;
161 std::memcpy(
162 buffer.cesium.data.data() + start,
163 gaussian.sh.data() + idx,
164 sizeof(float) * 3);
165 start += sizeof(float) * 3;
166 }
167}
168
169void decodePrimitive(

Callers 1

decodePrimitiveFunction · 0.85

Calls 4

findAccessorFunction · 0.85
formatFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected