BabylonExporter.GLTFExporter.Light.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using BabylonExport.Entities;
  2. using GLTFExport.Entities;
  3. namespace Max2Babylon
  4. {
  5. partial class BabylonExporter
  6. {
  7. private GLTFNode ExportLight(BabylonLight babylonLight, GLTF gltf, GLTFNode gltfParentNode)
  8. {
  9. RaiseMessage("GLTFExporter.Light | ExportLight babylonLight.name=" + babylonLight.name, 1);
  10. // --------------------------
  11. // ---------- Node ----------
  12. // --------------------------
  13. RaiseMessage("GLTFExporter.Light | Node", 2);
  14. // Node
  15. var gltfNode = new GLTFNode();
  16. gltfNode.name = babylonLight.name;
  17. gltfNode.index = gltf.NodesList.Count;
  18. gltf.NodesList.Add(gltfNode);
  19. // Hierarchy
  20. if (gltfParentNode != null)
  21. {
  22. RaiseMessage("GLTFExporter.Light | Add " + babylonLight.name + " as child to " + gltfParentNode.name, 3);
  23. gltfParentNode.ChildrenList.Add(gltfNode.index);
  24. }
  25. else
  26. {
  27. // It's a root node
  28. // Only root nodes are listed in a gltf scene
  29. RaiseMessage("GLTFExporter.Light | Add " + babylonLight.name + " as root node to scene", 3);
  30. gltf.scenes[0].NodesList.Add(gltfNode.index);
  31. }
  32. // Transform
  33. gltfNode.translation = babylonLight.position;
  34. // Switch from left to right handed coordinate system
  35. //gltfNode.translation[0] *= -1;
  36. // No rotation defined for babylon light. Use identity instead.
  37. gltfNode.rotation = new float[4] { 0, 0, 0, 1 };
  38. // No scaling defined for babylon light. Use identity instead.
  39. gltfNode.scale = new float[3] { 1, 1, 1 };
  40. return gltfNode;
  41. }
  42. }
  43. }