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

Function getColorAccessorView

CesiumGltf/src/AccessorUtility.cpp:267–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267ColorAccessorType getColorAccessorView(
268 const Model& model,
269 const MeshPrimitive& primitive,
270 int32_t colorSetIndex) {
271 std::string colorName = "COLOR_" + std::to_string(colorSetIndex);
272 auto colorIt = primitive.attributes.find(colorName);
273 if (colorIt == primitive.attributes.end()) {
274 return ColorAccessorType();
275 }
276
277 const Accessor* pAccessor =
278 model.getSafe<Accessor>(&model.accessors, colorIt->second);
279 if (!pAccessor) {
280 return ColorAccessorType();
281 }
282
283 if (pAccessor->type == Accessor::Type::VEC3) {
284 switch (pAccessor->componentType) {
285 case Accessor::ComponentType::UNSIGNED_BYTE:
286 if (pAccessor->normalized) {
287 return AccessorView<AccessorTypes::VEC3<uint8_t>>(model, *pAccessor);
288 } else {
289 // Invalid accessor, UNSIGNED_BYTE must be normalized
290 return ColorAccessorType();
291 }
292 case Accessor::ComponentType::UNSIGNED_SHORT:
293 if (pAccessor->normalized) {
294 return AccessorView<AccessorTypes::VEC3<uint16_t>>(model, *pAccessor);
295 } else {
296 // Invalid accessor, UNSIGNED_SHORT must be normalized
297 return ColorAccessorType();
298 }
299 case Accessor::ComponentType::FLOAT:
300 return AccessorView<AccessorTypes::VEC3<float>>(model, *pAccessor);
301 default:
302 return ColorAccessorType();
303 }
304 }
305
306 if (pAccessor->type == Accessor::Type::VEC4) {
307 switch (pAccessor->componentType) {
308 case Accessor::ComponentType::UNSIGNED_BYTE:
309 if (pAccessor->normalized) {
310 return AccessorView<AccessorTypes::VEC4<uint8_t>>(model, *pAccessor);
311 } else {
312 // Invalid accessor, UNSIGNED_BYTE must be normalized
313 return ColorAccessorType();
314 }
315 case Accessor::ComponentType::UNSIGNED_SHORT:
316 if (pAccessor->normalized) {
317 return AccessorView<AccessorTypes::VEC4<uint16_t>>(model, *pAccessor);
318 } else {
319 // Invalid accessor, UNSIGNED_SHORT must be normalized
320 return ColorAccessorType();
321 }
322 case Accessor::ComponentType::FLOAT:
323 return AccessorView<AccessorTypes::VEC4<float>>(model, *pAccessor);
324 default:

Callers 1

Calls 1

endMethod · 0.45

Tested by

no test coverage detected