Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //from nape.as, the Physics Editor (https://www.codeandweb.com/physicseditor) Nape-exporter template.
- //nape.as is located in [install directory]\CodeAndWeb\PhysicsEditor\resources\exporters\nape-as3\
- //Changes:
- //fixed typos: "{{body.cbType}}" => "{{body.cbTypes}}", "{{fixture.cbType}}" => "{{fixture.cbTypes}}"
- //added comment with body name at start of definition to help when navigating the source
- //changed s.body = body; => body.shapes.add(s) for my own peace of mind (clarify intention)
- private static function init():void {
- bodies = new Dictionary();
- var body:Body;
- var mat:Material;
- var filt:InteractionFilter;
- var prop:FluidProperties;
- var cbType:CbType;
- var s:Shape;
- var anchor:Vec2;
- {% for body in bodies %}
- //{{body.name}}
- body = new Body();
- cbtype(body.cbTypes,"{{body.cbTypes}}");
- {% for fixture in body.fixtures %}
- mat = material("{{fixture.material}}");
- filt = filter("{{fixture.filter}}");
- prop = fprop("{{fixture.fprop}}");
- {% if fixture.isCircle %}
- s = new Circle(
- {{fixture.radius}},
- Vec2.weak({{fixture.center.x}},{{fixture.center.y}}),
- mat,
- filt
- );
- body.shapes.add(s);
- s.sensorEnabled = {{fixture.sensorEnabled}};
- s.fluidEnabled = {{fixture.fluidEnabled}};
- s.fluidProperties = prop;
- cbtype(s.cbTypes,"{{fixture.cbTypes}}");
- {% else %}
- {% for polygon in fixture.polygons %}
- s = new Polygon(
- [ {% for point in polygon %} {% if not forloop.first %}, {% endif %} Vec2.weak({{point.x}},{{point.y}}) {% endfor %} ],
- mat,
- filt
- );
- body.shapes.add(s);
- s.sensorEnabled = {{fixture.sensorEnabled}};
- s.fluidEnabled = {{fixture.fluidEnabled}};
- s.fluidProperties = prop;
- cbtype(s.cbTypes,"{{fixture.cbTypes}}");
- {% endfor %}
- {% endif %}
- {% endfor %}
- anchor = ({{body.auto_anchor}}) ? body.localCOM.copy() : Vec2.get({{body.anchorPointAbs.x}},{{body.anchorPointAbs.y}});
- body.translateShapes(Vec2.weak(-anchor.x,-anchor.y));
- body.position.setxy(0,0);
- bodies["{{body.name}}"] = new BodyPair(body,anchor);
- {% endfor %}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement