MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / parse_khr_lights_punctual

Method parse_khr_lights_punctual

framework/gltf_loader.cpp:1566–1672  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1564}
1565
1566std::vector<std::unique_ptr<sg::Light>> GLTFLoader::parse_khr_lights_punctual()
1567{
1568 if (is_extension_enabled(KHR_LIGHTS_PUNCTUAL_EXTENSION))
1569 {
1570 if (model.extensions.find(KHR_LIGHTS_PUNCTUAL_EXTENSION) == model.extensions.end() || !model.extensions.at(KHR_LIGHTS_PUNCTUAL_EXTENSION).Has("lights"))
1571 {
1572 return {};
1573 }
1574 auto &khr_lights = model.extensions.at(KHR_LIGHTS_PUNCTUAL_EXTENSION).Get("lights");
1575
1576 std::vector<std::unique_ptr<sg::Light>> light_components(khr_lights.ArrayLen());
1577
1578 for (size_t light_index = 0; light_index < khr_lights.ArrayLen(); ++light_index)
1579 {
1580 auto &khr_light = khr_lights.Get(static_cast<int>(light_index));
1581
1582 // Spec states a light has to have a type to be valid
1583 if (!khr_light.Has("type"))
1584 {
1585 LOGE("KHR_lights_punctual extension: light {} doesn't have a type!", light_index);
1586 throw std::runtime_error("Couldn't load glTF file, KHR_lights_punctual extension is invalid");
1587 }
1588
1589 auto light = std::make_unique<sg::Light>(khr_light.Get("name").Get<std::string>());
1590
1591 sg::LightType type;
1592 sg::LightProperties properties;
1593
1594 // Get type
1595 auto &gltf_light_type = khr_light.Get("type").Get<std::string>();
1596 if (gltf_light_type == "point")
1597 {
1598 type = sg::LightType::Point;
1599 }
1600 else if (gltf_light_type == "spot")
1601 {
1602 type = sg::LightType::Spot;
1603 }
1604 else if (gltf_light_type == "directional")
1605 {
1606 type = sg::LightType::Directional;
1607 }
1608 else
1609 {
1610 LOGE("KHR_lights_punctual extension: light type '{}' is invalid", gltf_light_type);
1611 throw std::runtime_error("Couldn't load glTF file, KHR_lights_punctual extension is invalid");
1612 }
1613
1614 // Get properties
1615 if (khr_light.Has("color"))
1616 {
1617 properties.color = glm::vec3(
1618 static_cast<float>(khr_light.Get("color").Get(0).Get<double>()),
1619 static_cast<float>(khr_light.Get("color").Get(1).Get<double>()),
1620 static_cast<float>(khr_light.Get("color").Get(2).Get<double>()));
1621 }
1622
1623 if (khr_light.Has("intensity"))

Callers

nothing calls this directly

Calls 3

endMethod · 0.80
set_light_typeMethod · 0.80
set_propertiesMethod · 0.80

Tested by

no test coverage detected