BabylonExporter.GLTFExporter.Light.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. gltfNode.parent = gltfParentNode;
  25. }
  26. else
  27. {
  28. // It's a root node
  29. // Only root nodes are listed in a gltf scene
  30. RaiseMessage("GLTFExporter.Light | Add " + babylonLight.name + " as root node to scene", 3);
  31. gltf.scenes[0].NodesList.Add(gltfNode.index);
  32. }
  33. // Transform
  34. gltfNode.translation = babylonLight.position;
  35. // No rotation defined for babylon light. Use identity instead.
  36. gltfNode.rotation = new float[4] { 0, 0, 0, 1 };
  37. // No scaling defined for babylon light. Use identity instead.
  38. gltfNode.scale = new float[3] { 1, 1, 1 };
  39. // Animations
  40. ExportNodeAnimation(babylonLight, gltf, gltfNode);
  41. return gltfNode;
  42. }
  43. }
  44. }