Scene.hx 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package hrt.prefab;
  2. class Scene extends Prefab {
  3. override function load(obj:Dynamic) {
  4. }
  5. override function save() {
  6. return {};
  7. }
  8. override function makeInstance( ctx : Context ) {
  9. #if editor
  10. var scene = hide.comp.Scene.getCurrent();
  11. var obj = scene.loadModel(source, true);
  12. var cam = @:privateAccess scene.defaultCamera;
  13. // allow to add sub elements relative to camera target
  14. var root = new h3d.scene.Object(ctx.local3d);
  15. root.x = cam.target.x;
  16. root.y = cam.target.y;
  17. root.z = cam.target.z;
  18. obj.x -= root.x;
  19. obj.y -= root.y;
  20. obj.z -= root.z;
  21. root.addChild(obj);
  22. ctx = ctx.clone(this);
  23. ctx.local3d = root;
  24. #end
  25. return ctx;
  26. }
  27. #if editor
  28. override function getHideProps() : HideProps {
  29. return { icon : "cube", name : "Scene", fileSource : ["hsd"] };
  30. }
  31. #end
  32. static var _ = Library.register("scene", Scene);
  33. }