Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light reference in the node #458

Closed
Tugcga opened this issue Nov 11, 2023 · 3 comments
Closed

Light reference in the node #458

Tugcga opened this issue Nov 11, 2023 · 3 comments
Labels
bug extension glTF extension

Comments

@Tugcga
Copy link

Tugcga commented Nov 11, 2023

Describe the issue

When create GLTF file for the scene with lights, actual reference to the light does not assigned to the node.

To Reproduce

Minimal example with wrong output:

tinygltf::Model model;
tinygltf::Scene scene;

// setup the light
tinygltf::Light light;
light.name = "light";
light.type = "point";
light.intensity = 0.75;
light.color = std::vector<double>{1.0, 0.8, 0.95};

model.lights.push_back(light);

// setup the node
tinygltf::Node node;
node.name = "light_node";
// assign light to the node
node.light = 0;
// add to the model
model.nodes.push_back(node);
// and to the scene
scene.nodes.push_back(0);

scene.name = "scene_Name";
model.scenes.push_back(scene);
model.defaultScene = 0;

tinygltf::TinyGLTF gltf;
gltf.WriteGltfSceneToFile(&model, "output.gltf");

As a result it produce the following output.gltf:

{
  "asset": {
    "version": "2.0"
  },
  "extensions": {
    "KHR_lights_punctual": {
      "lights": [
        {
          "color": [
            1.0,
            0.8,
            0.95
          ],
          "intensity": 0.75,
          "name": "light",
          "type": "point"
        }
      ]
    }
  },
  "extensionsUsed": [
    "KHR_lights_punctual"
  ],
  "nodes": [
    {
      "extensions": {
        "KHR_lights_punctual": {}
      },
      "name": "light_node"
    }
  ],
  "scene": 0,
  "scenes": [
    {
      "name": "scene_Name",
      "nodes": [
        0
      ]
    }
  ]
}

Expected behaviour

The node with the name light_node should contains

"extensions": {
        "KHR_lights_punctual": {
          "light": 0
        }
      },

Possible solution

In the static void SerializeGltfNode(const Node &node, detail::json &o) function find the KHR_lights_punctual section in the json by using detail::FindMember(extensions, "KHR_lights_punctual", it); instead of detail::FindMember(o, "KHR_lights_punctual", it);

@syoyo
Copy link
Owner

syoyo commented Nov 11, 2023

Good find!

The spec says https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/README.md#adding-light-instances-to-nodes

So we need to list light ids in extensions.KHR_lights_punctual of node.

Probably we simply forget to serialize light ids to extensions.KHR_lights_punctual of node. PR is much appreciated!

@syoyo syoyo added bug extension glTF extension labels Nov 11, 2023
@ptc-tgamper
Copy link
Contributor

I screwed up the issue number in the commit message. This has been fixed by #463

@syoyo
Copy link
Owner

syoyo commented Nov 23, 2023

Thank you @ptc-tgamper, close this issue as resolved.

@syoyo syoyo closed this as completed Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug extension glTF extension
Projects
None yet
Development

No branches or pull requests

3 participants