SHARE
TWEET

nape.as, Physics Editor export template

ulfben Feb 17th, 2016 (edited) 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //from nape.as, the Physics Editor (https://www.codeandweb.com/physicseditor) Nape-exporter template.
  2. //nape.as is located in [install directory]\CodeAndWeb\PhysicsEditor\resources\exporters\nape-as3\
  3. //Changes:
  4.     //fixed typos: "{{body.cbType}}" => "{{body.cbTypes}}", "{{fixture.cbType}}" => "{{fixture.cbTypes}}"
  5.     //added comment with body name at start of definition to help when navigating the source
  6.     //changed s.body = body; => body.shapes.add(s) for my own peace of mind (clarify intention)
  7.  
  8. private static function init():void {
  9.         bodies = new Dictionary();
  10.  
  11.         var body:Body;
  12.         var mat:Material;
  13.         var filt:InteractionFilter;
  14.         var prop:FluidProperties;
  15.         var cbType:CbType;
  16.         var s:Shape;
  17.         var anchor:Vec2;
  18.  
  19.         {% for body in bodies %}
  20.             //{{body.name}}
  21.             body = new Body();
  22.             cbtype(body.cbTypes,"{{body.cbTypes}}");
  23.             {% for fixture in body.fixtures %}
  24.                 mat = material("{{fixture.material}}");
  25.                 filt = filter("{{fixture.filter}}");
  26.                 prop = fprop("{{fixture.fprop}}");
  27.                 {% if fixture.isCircle %}
  28.                     s = new Circle(
  29.                         {{fixture.radius}},
  30.                         Vec2.weak({{fixture.center.x}},{{fixture.center.y}}),
  31.                         mat,
  32.                         filt
  33.                     );
  34.                     body.shapes.add(s);
  35.                     s.sensorEnabled = {{fixture.sensorEnabled}};
  36.                     s.fluidEnabled = {{fixture.fluidEnabled}};
  37.                     s.fluidProperties = prop;
  38.                     cbtype(s.cbTypes,"{{fixture.cbTypes}}");
  39.                 {% else %}
  40.                     {% for polygon in fixture.polygons %}
  41.                     s = new Polygon(
  42.                         [ {% for point in polygon %} {% if not forloop.first %}, {% endif %} Vec2.weak({{point.x}},{{point.y}})  {% endfor %} ],
  43.                         mat,
  44.                         filt
  45.                     );
  46.                     body.shapes.add(s);
  47.                     s.sensorEnabled = {{fixture.sensorEnabled}};
  48.                     s.fluidEnabled = {{fixture.fluidEnabled}};
  49.                     s.fluidProperties = prop;
  50.                     cbtype(s.cbTypes,"{{fixture.cbTypes}}");
  51.                     {% endfor %}
  52.                 {% endif %}
  53.             {% endfor %}
  54.             anchor = ({{body.auto_anchor}}) ? body.localCOM.copy() : Vec2.get({{body.anchorPointAbs.x}},{{body.anchorPointAbs.y}});
  55.             body.translateShapes(Vec2.weak(-anchor.x,-anchor.y));
  56.             body.position.setxy(0,0);
  57.             bodies["{{body.name}}"] = new BodyPair(body,anchor);
  58.         {% endfor %}
  59.     }
RAW Paste Data
Top