From 786f3075c5d7931d38414ff7f719e3a08bfe6340 Mon Sep 17 00:00:00 2001 From: maho Date: Fri, 12 May 2017 22:28:49 +0200 Subject: [PATCH 1/5] - concave shapes, very inefficient --- .../17-concave-phys-objects/.vewpostactivate | 1 + examples/17-concave-phys-objects/main.py | 194 ++++++++++++++++++ examples/17-concave-phys-objects/objects.svg | 125 +++++++++++ .../poscolorshader.glsl | 38 ++++ .../17-concave-phys-objects/yourappname.kv | 82 ++++++++ 5 files changed, 440 insertions(+) create mode 100644 examples/17-concave-phys-objects/.vewpostactivate create mode 100644 examples/17-concave-phys-objects/main.py create mode 100644 examples/17-concave-phys-objects/objects.svg create mode 100644 examples/17-concave-phys-objects/poscolorshader.glsl create mode 100644 examples/17-concave-phys-objects/yourappname.kv diff --git a/examples/17-concave-phys-objects/.vewpostactivate b/examples/17-concave-phys-objects/.vewpostactivate new file mode 100644 index 00000000..bc5b6ed8 --- /dev/null +++ b/examples/17-concave-phys-objects/.vewpostactivate @@ -0,0 +1 @@ +kh2 diff --git a/examples/17-concave-phys-objects/main.py b/examples/17-concave-phys-objects/main.py new file mode 100644 index 00000000..3f25c740 --- /dev/null +++ b/examples/17-concave-phys-objects/main.py @@ -0,0 +1,194 @@ +from kivy.app import App +from kivy.logger import Logger +from kivy.uix.widget import Widget +from kivy.clock import Clock +from kivy.core.window import Window +from kivy.vector import Vector +from random import randint, choice +from math import radians, pi, sin, cos +import kivent_core +import kivent_cymunk +from kivent_core.gameworld import GameWorld +from kivent_core.managers.resource_managers import texture_manager + +from kivent_core.rendering.svg_loader import SVGModelInfo +from kivent_core.systems.renderers import RotateRenderer +from kivent_core.systems.position_systems import PositionSystem2D +from kivent_core.systems.rotate_systems import RotateSystem2D +from kivent_cymunk.interaction import CymunkTouchSystem +from kivy.properties import StringProperty, NumericProperty +from functools import partial +from os.path import dirname, join, abspath + +texture_manager.load_atlas(join(dirname(dirname(abspath(__file__))), 'assets', + 'background_objects.atlas')) + +def cross(v1, v2): + return v1.x*v2.y - v1.y*v2.x + +def fix_winding(verts): + v1 = Vector(verts[0]) - Vector(verts[1]) + v2 = Vector(verts[1]) - Vector(verts[2]) + v3 = Vector(verts[2]) - Vector(verts[0]) + + v1x2 = cross(v1, v2) + v2x3 = cross(v2, v3) + + if abs(v1x2) < 1.0 or abs(v2x3) < 1.0: + return None + + if v1x2 < 0: + return verts + else: + return verts[::-1] + + +class TestGame(Widget): + def __init__(self, **kwargs): + super(TestGame, self).__init__(**kwargs) + self.gameworld.init_gameworld( + ['cymunk_physics', 'poly_renderer', 'rotate', 'position', 'cymunk_touch' ], + callback=self.init_game) + + def init_game(self): + self.setup_states() + self.set_state() + self.draw_some_stuff() + + def destroy_created_entity(self, ent_id, dt): + self.gameworld.remove_entity(ent_id) + self.app.count -= 1 + + def draw_some_stuff(self): + + self.load_svg('objects.svg', self.gameworld) + + def normalize_info(self, info): + def _median(li): + li = sorted(li) + lenli = len(li) + if lenli % 2: + return li[lenli//2] + else: + return (li[lenli//2 - 1] + li[lenli//2])/2.0 + + #first - calculate (very roughly middle of the object), median + xmid = _median([ x['pos'][0] for x in info.vertices.values()]) + ymid = _median([ x['pos'][1] for x in info.vertices.values()]) + + ret = SVGModelInfo(info.indices, + info.vertices.copy(), + custom_data=info.custom_data, + description=info.description, + element_id=info.element_id, + title=info.title, + path_vertices=info.path_vertices[:] + ) + + #now substract it from vertices + for k in ret.vertices: + v = ret.vertices[k].copy() + x, y = v['pos'] + v['pos'] = (x - xmid, y - ymid) + ret.vertices[k] = v + + #and path vertices + for i, (x, y) in enumerate(ret.path_vertices): + ret.path_vertices[i] = (x - xmid, y - ymid) + + return ret, (xmid, ymid) + + + def load_svg(self, fname, gameworld): + mm = gameworld.model_manager + data = mm.get_model_info_for_svg(fname) + + for info in data['model_info']: + + pos = (randint(0, 200), randint(0, 200)) + #info, pos = self.normalize_info(info) + + Logger.debug("adding object with title/element_id=%s/%s and desc=%s", info.title, info.element_id, info.description) + model_name = mm.load_model_from_model_info(info, data['svg_name']) + + indices = info.indices[:] + shapeno = 0 + shapes = [] + while indices: + tr_indices, indices = indices[:3], indices[3:] + tr_verts = [info.vertices[x]['pos'] for x in tr_indices] + + tr_verts = fix_winding(tr_verts) + if tr_verts is None: + continue + + triangle_shape = { + 'shape_type': 'poly', + 'elasticity': 0.6, + 'collision_type': 1, + 'friction': 1.0, + 'shape_info': { + 'mass': 50, + 'offset': (0, 0), + 'vertices': tr_verts + } + + } + Logger.debug("shape %s added", shapeno) + shapeno += 1 + shapes.append(triangle_shape) + + + + physics = { + 'main_shape': 'poly', + 'velocity': (0, 0), + 'position': pos, + 'angle': 0, + 'angular_velocity': radians(0), + 'ang_vel_limit': radians(0), + 'mass': 50, + 'col_shapes': shapes + } + + create_dict = { + 'position': pos, + 'poly_renderer': {'model_key': model_name}, + 'cymunk_physics': physics, + 'rotate': radians(0), + } + + ent = gameworld.init_entity(create_dict, ['position', 'rotate', 'poly_renderer', 'cymunk_physics']) + self.app.count += 1 + + def update(self, dt): + self.gameworld.update(dt) + + def setup_states(self): + self.gameworld.add_state(state_name='main', + systems_added=['poly_renderer'], + systems_removed=[], systems_paused=[], + systems_unpaused=['poly_renderer'], + screenmanager_screen='main') + + def set_state(self): + self.gameworld.state = 'main' + + +class DebugPanel(Widget): + fps = StringProperty(None) + + def __init__(self, **kwargs): + super(DebugPanel, self).__init__(**kwargs) + Clock.schedule_once(self.update_fps) + + def update_fps(self,dt): + self.fps = str(int(Clock.get_fps())) + Clock.schedule_once(self.update_fps, .05) + +class YourAppNameApp(App): + count = NumericProperty(0) + + +if __name__ == '__main__': + YourAppNameApp().run() diff --git a/examples/17-concave-phys-objects/objects.svg b/examples/17-concave-phys-objects/objects.svg new file mode 100644 index 00000000..8fdd3531 --- /dev/null +++ b/examples/17-concave-phys-objects/objects.svg @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/examples/17-concave-phys-objects/poscolorshader.glsl b/examples/17-concave-phys-objects/poscolorshader.glsl new file mode 100644 index 00000000..c64f82ce --- /dev/null +++ b/examples/17-concave-phys-objects/poscolorshader.glsl @@ -0,0 +1,38 @@ +---VERTEX SHADER--- +#ifdef GL_ES + precision highp float; +#endif + +/* Outputs to the fragment shader */ +varying vec4 frag_color; + +/* vertex attributes */ +attribute vec2 pos; +attribute vec4 v_color; + + +/* uniform variables */ +uniform mat4 modelview_mat; +uniform mat4 projection_mat; +uniform vec4 color; +uniform float opacity; + +void main (void) { + frag_color = v_color*color; + vec4 pos = vec4(pos.xy, 0.0, 1.0); + gl_Position = projection_mat * modelview_mat * pos; + +} + + +---FRAGMENT SHADER--- +#ifdef GL_ES + precision highp float; +#endif + +/* Outputs from the vertex shader */ +varying vec4 frag_color; + +void main (void){ + gl_FragColor = frag_color; +} diff --git a/examples/17-concave-phys-objects/yourappname.kv b/examples/17-concave-phys-objects/yourappname.kv new file mode 100644 index 00000000..cb50eb26 --- /dev/null +++ b/examples/17-concave-phys-objects/yourappname.kv @@ -0,0 +1,82 @@ +#:kivy 1.9.0 +#:import path os.path +#:import dirname os.path.dirname +#:import main __main__ + +TestGame: + +: + gameworld: gameworld + app: app + GameWorld: + id: gameworld + gamescreenmanager: gamescreenmanager + size_of_gameworld: 100*1024 + zones: {'general': 20000, 'touch': 100} + model_format_allocations: {'vertex_format_2f4ub': (150*1024, 150*1024),'vertex_format_4f': (150*1024, 150*1024) } + PositionSystem2D: + system_id: 'position' + gameworld: gameworld + zones: ['general', 'touch'] + + RotateSystem2D: + system_id: 'rotate' + gameworld: gameworld + zones: ['general'] + + PolyRenderer: + id: 'poly_renderer' + system_id: 'poly_renderer' + gameworld: gameworld + zones: ['general'] + frame_count: 2 + updateable: True + shader_source: 'poscolorshader.glsl' + + CymunkPhysics: + gameworld: root.gameworld + zones: ['general'] + + CymunkTouchSystem: + gameworld: root.gameworld + zones: ['touch'] + zone_to_use: 'touch' + physics_system: 'cymunk_physics' + touch_radius: 30 + + GameScreenManager: + id: gamescreenmanager + size: root.size + pos: root.pos + gameworld: gameworld + +: + MainScreen: + id: main_screen + +: + name: 'main' + FloatLayout: + Button: + text: 'Draw Some Stuff' + size_hint: (.2, .1) + pos_hint: {'x': .025, 'y': .025} + on_release: app.root.draw_some_stuff() + DebugPanel: + size_hint: (.2, .1) + pos_hint: {'x': .225, 'y': .025} + Label: + text: str(app.count) + size_hint: (.2, .1) + font_size: 24 + pos_hint: {'x': .425, 'y': .025} + +: + Label: + pos: root.pos + size: root.size + font_size: root.size[1]*.5 + halign: 'center' + valign: 'middle' + color: (1,1,1,1) + text: 'FPS: ' + root.fps if root.fps != None else 'FPS:' From bc62e93d3ebfe243c262bf116d16db8c2a98bba8 Mon Sep 17 00:00:00 2001 From: maho Date: Tue, 16 May 2017 13:26:47 +0200 Subject: [PATCH 2/5] - a bit more efficient way of adding concave polys --- .../17-concave-phys-objects/concave2convex.py | 190 ++++++++++++++++++ examples/17-concave-phys-objects/debugdraw.py | 40 ++++ examples/17-concave-phys-objects/main.py | 88 ++------ examples/17-concave-phys-objects/objects.svg | 37 +--- 4 files changed, 254 insertions(+), 101 deletions(-) create mode 100644 examples/17-concave-phys-objects/concave2convex.py create mode 100644 examples/17-concave-phys-objects/debugdraw.py diff --git a/examples/17-concave-phys-objects/concave2convex.py b/examples/17-concave-phys-objects/concave2convex.py new file mode 100644 index 00000000..b1f910bc --- /dev/null +++ b/examples/17-concave-phys-objects/concave2convex.py @@ -0,0 +1,190 @@ +import json +import os +import signal + +from kivy.logger import Logger +from kivy.vector import Vector + + +def bisect_iter(ilist): + if len(ilist) <= 2: + for x in ilist: + yield x + return + + mid = int(len(ilist)/2) + yield ilist[mid] + + for x in bisect_iter(ilist[:mid]): + yield x + + for x in bisect_iter(ilist[mid + 1:]): + yield x + +def uniq(plist): + ret = [] + for x in plist: + if x not in ret: + ret.append(x) + return ret + + +def cross(v1, v2): + return v1.x*v2.y - v1.y*v2.x + +def area(verts): + area = 0.0 + for v1,v2,v3 in zip(verts, verts[1:] + verts[:1], verts[2:] + verts[:2]): + vec1 = Vector(v2) - Vector(v1) + vec2 = Vector(v3) - Vector(v2) + + area += cross(vec1, vec2) + return area + +def fix_winding(verts): + + poly_area = area(verts) + + if poly_area < 0: + return verts + else: + return verts[::-1] + +def is_convex(verts): + for v1,v2,v3 in zip(verts, verts[1:] + verts[:1], verts[2:] + verts[:2]): + vec1 = Vector(v2) - Vector(v1) + vec2 = Vector(v3) - Vector(v2) + + cr = cross(vec1, vec2) + if cr == 0 and vec1.dot(vec2) < 0: + return False + if cross(vec1, vec2) > 0: + return False + + return True + +def split_path(path, vertsplit): + left = path[:vertsplit] + right = path[vertsplit-1:] + [path[0]] + + if hasattr(split_path, 'debug'): + gnuplot_verts(path, left, right) + + return left, right + +def point_in_poly(verts, point): + #vectors of path + vertpairs = zip(verts, verts[1:] + verts[:1]) + + side = None + for vert1, vert2 in vertpairs: + vec1 = Vector(vert2) - Vector(vert1) + vec2 = Vector(point) - Vector(vert1) + vec1xvec2 = cross(vec1, vec2) + if vec1xvec2 == 0: + continue + + if side is None: + side = vec1xvec2 + + if side < 0 and vec1xvec2 > 0: + return False + + if side > 0 and vec1xvec2 < 0: + return False + + return True + + + +def intersects_with_remaining(path, remaining): + + for rv in bisect_iter(remaining[1:-1]): + if point_in_poly(path, rv): + return True + return False + + +def signaltrace(signal, frame): + import pudb;pudb.set_trace()#TODO:FIXME:DEBUG:remove this breakpoint + +def concave2convex(path, desired_area=0.1, min_area=0.01): + + path = uniq(path) + path_area = area(path) + + desired_area *= path_area + min_area *= path_area + + path = fix_winding(path) + debug_polys = [] + + rotate_cnt = 0 + while True: + lgpiece = None + lgremain = None + lgarea = 0 + if is_convex(path): + yield path + return + for splitvert in range(3, len(path)): + piece, remaining = split_path(path, splitvert) + piece_is_convex = is_convex(piece) + if piece_is_convex and is_convex(remaining): + yield piece + yield remaining + return + if not piece_is_convex or intersects_with_remaining(piece, remaining): + if not lgpiece or not lgremain or lgarea > -desired_area: + #rotate path + rotate_cnt+=1 + Logger.debug("rotate path no %s", rotate_cnt) + path = path[1:] + path[:1] + if rotate_cnt >= len(path): + desired_area /= 2 + Logger.debug("desired area is now %s", desired_area) + if desired_area <= min_area: + Logger.debug("which is below minimum, exiting") + return + rotate_cnt = 0 + break + yield lgpiece + path = lgremain + break + lgpiece = piece + lgremain = remaining + lgarea = area(lgpiece) + +def cached_c2c(path, cache_dir=".convexpolys", **kwargs): + pathhash = str(hash(tuple(path))) + fname = os.path.join(cache_dir, pathhash) + try: + fp = open(fname, "r") + return json.load(fp) + except IOError: + try: + os.makedirs(cache_dir) + except OSError: + if not os.path.isdir(cache_dir): + raise + fp = open(fname, "w") + ret = list(concave2convex(path, **kwargs)) + json.dump(ret, fp) + fp.close() + return ret + + +if __name__ == '__main__': + from debugdraw import gnuplot_verts + + for x in concave2convex([(0,0), (0,2), (1,1), (2,2), (2,0), (1, 0.5)]): + gnuplot_verts(x) + + + + + + + + + diff --git a/examples/17-concave-phys-objects/debugdraw.py b/examples/17-concave-phys-objects/debugdraw.py new file mode 100644 index 00000000..904e7677 --- /dev/null +++ b/examples/17-concave-phys-objects/debugdraw.py @@ -0,0 +1,40 @@ +import itertools +from math import ceil, sqrt +import os + + +def gnuplot_verts(*vss): + f = open("/tmp/ee.plt", "w") + + minr, maxr = 999999, -9999999 + for path in vss: + for vert in path: + for coord in vert: + minr = min(minr, coord) + maxr = max(maxr, coord) + + numplots = len(vss) + inrow = int(ceil(sqrt(numplots))) + numrows = int(ceil(float(numplots)/inrow)) + + f.write('set terminal pdfcairo font "arial, 9" size 30cm,30cm \n') + f.write('set output "/tmp/ee.pdf"\n') + f.write("set multiplot layout %s, %s\n"%(numrows, inrow)) + f.write("set size ratio -1\n") + for vs in vss: + + #f.write("set xrange[%s:%s]\n"%(minr-1, maxr+1)) + #f.write("set yrange[%s:%s]\n"%(minr-1, maxr+1)) + + f.write("plot '-' u 1:2:3:4 w vectors\n") + for (fx, fy),(tx, ty) in zip(vs[:-1], vs[1:]): + f.write("%s %s %s %s\n"%(fx, fy, (tx-fx), (ty-fy))) + + f.write("e\n") + f.close() + os.system("gnuplot /tmp/ee.plt -persist") + + +if __name__ == '__main__': + gnuplot_verts([(0, 0), (0,1), (1,1), (1, 0)], + [(1,1), (2,2), (3,2), (4,0)]) diff --git a/examples/17-concave-phys-objects/main.py b/examples/17-concave-phys-objects/main.py index 3f25c740..0ede19dc 100644 --- a/examples/17-concave-phys-objects/main.py +++ b/examples/17-concave-phys-objects/main.py @@ -1,11 +1,14 @@ +from functools import partial +from os.path import dirname, join, abspath +from random import randint, choice +from math import radians, pi, sin, cos + from kivy.app import App from kivy.logger import Logger from kivy.uix.widget import Widget from kivy.clock import Clock from kivy.core.window import Window from kivy.vector import Vector -from random import randint, choice -from math import radians, pi, sin, cos import kivent_core import kivent_cymunk from kivent_core.gameworld import GameWorld @@ -17,30 +20,13 @@ from kivent_core.systems.rotate_systems import RotateSystem2D from kivent_cymunk.interaction import CymunkTouchSystem from kivy.properties import StringProperty, NumericProperty -from functools import partial -from os.path import dirname, join, abspath + +from concave2convex import concave2convex, cached_c2c +from debugdraw import gnuplot_verts texture_manager.load_atlas(join(dirname(dirname(abspath(__file__))), 'assets', 'background_objects.atlas')) -def cross(v1, v2): - return v1.x*v2.y - v1.y*v2.x - -def fix_winding(verts): - v1 = Vector(verts[0]) - Vector(verts[1]) - v2 = Vector(verts[1]) - Vector(verts[2]) - v3 = Vector(verts[2]) - Vector(verts[0]) - - v1x2 = cross(v1, v2) - v2x3 = cross(v2, v3) - - if abs(v1x2) < 1.0 or abs(v2x3) < 1.0: - return None - - if v1x2 < 0: - return verts - else: - return verts[::-1] class TestGame(Widget): @@ -63,66 +49,22 @@ def draw_some_stuff(self): self.load_svg('objects.svg', self.gameworld) - def normalize_info(self, info): - def _median(li): - li = sorted(li) - lenli = len(li) - if lenli % 2: - return li[lenli//2] - else: - return (li[lenli//2 - 1] + li[lenli//2])/2.0 - - #first - calculate (very roughly middle of the object), median - xmid = _median([ x['pos'][0] for x in info.vertices.values()]) - ymid = _median([ x['pos'][1] for x in info.vertices.values()]) - - ret = SVGModelInfo(info.indices, - info.vertices.copy(), - custom_data=info.custom_data, - description=info.description, - element_id=info.element_id, - title=info.title, - path_vertices=info.path_vertices[:] - ) - - #now substract it from vertices - for k in ret.vertices: - v = ret.vertices[k].copy() - x, y = v['pos'] - v['pos'] = (x - xmid, y - ymid) - ret.vertices[k] = v - - #and path vertices - for i, (x, y) in enumerate(ret.path_vertices): - ret.path_vertices[i] = (x - xmid, y - ymid) - - return ret, (xmid, ymid) - - def load_svg(self, fname, gameworld): mm = gameworld.model_manager data = mm.get_model_info_for_svg(fname) for info in data['model_info']: - pos = (randint(0, 200), randint(0, 200)) - #info, pos = self.normalize_info(info) + pos = (randint(0, 600), randint(0, 400)) Logger.debug("adding object with title/element_id=%s/%s and desc=%s", info.title, info.element_id, info.description) model_name = mm.load_model_from_model_info(info, data['svg_name']) - indices = info.indices[:] shapeno = 0 shapes = [] - while indices: - tr_indices, indices = indices[:3], indices[3:] - tr_verts = [info.vertices[x]['pos'] for x in tr_indices] - - tr_verts = fix_winding(tr_verts) - if tr_verts is None: - continue - - triangle_shape = { + for poly in cached_c2c(info.path_vertices): + + shape = { 'shape_type': 'poly', 'elasticity': 0.6, 'collision_type': 1, @@ -130,13 +72,15 @@ def load_svg(self, fname, gameworld): 'shape_info': { 'mass': 50, 'offset': (0, 0), - 'vertices': tr_verts + 'vertices': poly } } Logger.debug("shape %s added", shapeno) shapeno += 1 - shapes.append(triangle_shape) + shapes.append(shape) + + #gnuplot_verts(*[x['shape_info']['vertices'] for x in shapes]) diff --git a/examples/17-concave-phys-objects/objects.svg b/examples/17-concave-phys-objects/objects.svg index 8fdd3531..1e7af587 100644 --- a/examples/17-concave-phys-objects/objects.svg +++ b/examples/17-concave-phys-objects/objects.svg @@ -31,7 +31,7 @@ id="namedview8" showgrid="false" inkscape:zoom="0.9833334" - inkscape:cx="295.41631" + inkscape:cx="-54.414175" inkscape:cy="238.08568" inkscape:window-x="1916" inkscape:window-y="-3" @@ -39,6 +39,10 @@ inkscape:current-layer="svg5084" /> + - - From d6c901b53b37bcb53844a98c824838ab5a43259c Mon Sep 17 00:00:00 2001 From: maho Date: Tue, 16 May 2017 20:54:25 +0200 Subject: [PATCH 3/5] - cache polys --- .../17-concave-phys-objects/concave2convex.py | 3 +- examples/17-concave-phys-objects/debugdraw.py | 28 +++++++++++++------ examples/17-concave-phys-objects/main.py | 4 +-- examples/17-concave-phys-objects/objects.svg | 8 +++--- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/examples/17-concave-phys-objects/concave2convex.py b/examples/17-concave-phys-objects/concave2convex.py index b1f910bc..810ee7d8 100644 --- a/examples/17-concave-phys-objects/concave2convex.py +++ b/examples/17-concave-phys-objects/concave2convex.py @@ -117,7 +117,6 @@ def concave2convex(path, desired_area=0.1, min_area=0.01): min_area *= path_area path = fix_winding(path) - debug_polys = [] rotate_cnt = 0 while True: @@ -156,7 +155,7 @@ def concave2convex(path, desired_area=0.1, min_area=0.01): lgarea = area(lgpiece) def cached_c2c(path, cache_dir=".convexpolys", **kwargs): - pathhash = str(hash(tuple(path))) + pathhash = str(hash(tuple(path + kwargs.items()))) fname = os.path.join(cache_dir, pathhash) try: fp = open(fname, "r") diff --git a/examples/17-concave-phys-objects/debugdraw.py b/examples/17-concave-phys-objects/debugdraw.py index 904e7677..886713f7 100644 --- a/examples/17-concave-phys-objects/debugdraw.py +++ b/examples/17-concave-phys-objects/debugdraw.py @@ -3,7 +3,10 @@ import os -def gnuplot_verts(*vss): +def gnuplot_verts(*vss, **kwargs): + pdf = kwargs.get("pdf", True) + single = kwargs.get("single", False) + closed = kwargs.get("closed", True) f = open("/tmp/ee.plt", "w") minr, maxr = 999999, -9999999 @@ -17,20 +20,29 @@ def gnuplot_verts(*vss): inrow = int(ceil(sqrt(numplots))) numrows = int(ceil(float(numplots)/inrow)) - f.write('set terminal pdfcairo font "arial, 9" size 30cm,30cm \n') - f.write('set output "/tmp/ee.pdf"\n') - f.write("set multiplot layout %s, %s\n"%(numrows, inrow)) + if pdf: + f.write('set terminal pdfcairo font "arial, 9" size 30cm,30cm \n') + f.write('set output "/tmp/ee.pdf"\n') + if not single: + f.write("set multiplot layout %s, %s\n"%(numrows, inrow)) f.write("set size ratio -1\n") + if single: + f.write("plot '-' u 1:2:3:4 w vectors\n") for vs in vss: #f.write("set xrange[%s:%s]\n"%(minr-1, maxr+1)) #f.write("set yrange[%s:%s]\n"%(minr-1, maxr+1)) - - f.write("plot '-' u 1:2:3:4 w vectors\n") - for (fx, fy),(tx, ty) in zip(vs[:-1], vs[1:]): + if not single: + f.write("plot '-' u 1:2:3:4 w vectors\n") + + for (fx, fy),(tx, ty) in (zip(vs, vs[1:] + vs[:1]) if closed else zip(vs[:-1], vs[1:])): f.write("%s %s %s %s\n"%(fx, fy, (tx-fx), (ty-fy))) - + + if not single: + f.write("e\n") + if single: f.write("e\n") + f.close() os.system("gnuplot /tmp/ee.plt -persist") diff --git a/examples/17-concave-phys-objects/main.py b/examples/17-concave-phys-objects/main.py index 0ede19dc..a6f3b5c5 100644 --- a/examples/17-concave-phys-objects/main.py +++ b/examples/17-concave-phys-objects/main.py @@ -62,7 +62,7 @@ def load_svg(self, fname, gameworld): shapeno = 0 shapes = [] - for poly in cached_c2c(info.path_vertices): + for poly in cached_c2c(info.path_vertices, min_area=0.00001): shape = { 'shape_type': 'poly', @@ -80,7 +80,7 @@ def load_svg(self, fname, gameworld): shapeno += 1 shapes.append(shape) - #gnuplot_verts(*[x['shape_info']['vertices'] for x in shapes]) + gnuplot_verts(*[x['shape_info']['vertices'] for x in shapes], single=True, pdf=False) diff --git a/examples/17-concave-phys-objects/objects.svg b/examples/17-concave-phys-objects/objects.svg index 1e7af587..9b1692da 100644 --- a/examples/17-concave-phys-objects/objects.svg +++ b/examples/17-concave-phys-objects/objects.svg @@ -31,7 +31,7 @@ id="namedview8" showgrid="false" inkscape:zoom="0.9833334" - inkscape:cx="-54.414175" + inkscape:cx="-268.99043" inkscape:cy="238.08568" inkscape:window-x="1916" inkscape:window-y="-3" @@ -97,8 +97,8 @@ From 216822f680cad09ff7ae349fc816a8a9effeb9a3 Mon Sep 17 00:00:00 2001 From: maho Date: Wed, 17 May 2017 14:37:49 +0200 Subject: [PATCH 4/5] - not very efficient, but split poly to convex shapes works. However, problem with collision detecting --- .../.convexpolys/-5187266973737743100 | 1 + .../.convexpolys/1136951465492135774 | 1 + .../17-concave-phys-objects/concave2convex.py | 222 ++++++++---------- examples/17-concave-phys-objects/debugdraw.py | 48 ++-- examples/17-concave-phys-objects/main.py | 26 +- examples/17-concave-phys-objects/objects.svg | 22 +- 6 files changed, 156 insertions(+), 164 deletions(-) create mode 100644 examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 create mode 100644 examples/17-concave-phys-objects/.convexpolys/1136951465492135774 diff --git a/examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 b/examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 new file mode 100644 index 00000000..13c0788a --- /dev/null +++ b/examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 @@ -0,0 +1 @@ +[[[13.899310111999512, 84.99319458007812], [13.347455978393555, 85.22177124023438], [12.873567581176758, 85.58541870117188], [12.509940147399902, 86.05929565429688], [12.281354904174805, 86.61114501953125], [12.203388214111328, 87.203369140625], [12.281354904174805, 87.79559326171875], [12.509940147399902, 88.34744262695312], [12.873567581176758, 88.82131958007812], [13.347455978393555, 89.18496704101562], [13.899310111999512, 89.41354370117188], [14.491523742675781, 89.49151611328125], [15.083736419677734, 89.41354370117188], [15.635591506958008, 89.18496704101562], [16.109479904174805, 88.82131958007812], [16.473106384277344, 88.34744262695312], [16.701692581176758, 87.79559326171875], [16.779659271240234, 87.203369140625], [16.701692581176758, 86.61114501953125], [16.473106384277344, 86.05929565429688], [16.109479904174805, 85.58541870117188], [15.635591506958008, 85.22177124023438], [15.083736419677734, 84.99319458007812], [14.491523742675781, 84.91522216796875]]] \ No newline at end of file diff --git a/examples/17-concave-phys-objects/.convexpolys/1136951465492135774 b/examples/17-concave-phys-objects/.convexpolys/1136951465492135774 new file mode 100644 index 00000000..d07441c9 --- /dev/null +++ b/examples/17-concave-phys-objects/.convexpolys/1136951465492135774 @@ -0,0 +1 @@ +[[[6.367440223693848, -200.77423095703125], [-2.4026951789855957, -199.735107421875], [-11.125282287597656, -198.3558349609375], [-19.78165054321289, -196.627685546875], [-28.353118896484375, -194.5413818359375], [-36.82102584838867, -192.08795166015625], [-45.16668701171875, -189.25848388671875], [-53.37143325805664, -186.04388427734375], [2.3814239501953125, -186.11163330078125], [13.111351013183594, -187.2626953125], [14.468262672424316, -188.17547607421875], [15.575579643249512, -189.34173583984375], [16.430946350097656, -190.70843505859375], [17.032014846801758, -192.22344970703125], [17.37643051147461, -193.833984375], [17.461843490600586, -195.487548828125], [17.285905838012695, -197.1318359375], [16.846261978149414, -198.714111328125], [16.140560150146484, -200.18182373046875], [15.166451454162598, -201.4825439453125]], [[2.3814239501953125, -186.11163330078125], [-53.37143325805664, -186.04388427734375], [-61.416587829589844, -182.43505859375], [-8.262374877929688, -184.3533935546875]], [[-8.262374877929688, -184.3533935546875], [-61.416587829589844, -182.43505859375], [-68.01629878190201, -179.0693359375], [-18.790969848632812, -182.00140380859375]], [[-18.790969848632812, -182.00140380859375], [-68.01629878190201, -179.0693359375], [-69.28348541259766, -178.423095703125], [-29.175262451171875, -179.0693359375]], [[-29.175262451171875, -179.0693359375], [-69.28348541259766, -178.423095703125], [-80.88998724890138, -171.5186767578125], [-39.38617706298828, -175.570556640625]], [[-39.38617706298828, -175.570556640625], [-80.88998724890138, -171.5186767578125], [-88.17408752441406, -167.185546875], [-49.39461898803711, -171.5186767578125]], [[-49.39461898803711, -171.5186767578125], [-88.17408752441406, -167.185546875], [-95.38882592100362, -161.80889892578125], [-59.17149353027344, -166.92681884765625]], [[-59.17149353027344, -166.92681884765625], [-95.38882592100362, -161.80889892578125], [-102.94468185992774, -156.17803955078125], [-68.68772888183594, -161.80889892578125]], [[-68.68772888183594, -161.80889892578125], [-102.94468185992774, -156.17803955078125], [-105.84479522705078, -154.01678466796875], [-77.9142074584961, -156.17803955078125]], [[-77.9142074584961, -156.17803955078125], [-105.84479522705078, -154.01678466796875], [-122.12613677978516, -139.100830078125], [-86.82188415527344, -150.0479736328125]], [[-86.82188415527344, -150.0479736328125], [-122.12613677978516, -139.100830078125], [-136.53560024143127, -122.97271728515625], [-102.65865325927734, -137.30859375]], [[-102.65865325927734, -137.30859375], [-136.53560024143127, -122.97271728515625], [-136.84866333007812, -122.622314453125], [-117.0555648803711, -122.97271728515625]], [[-117.0555648803711, -122.97271728515625], [-136.84866333007812, -122.622314453125], [-149.8428955078125, -104.765380859375], [-129.90701293945312, -107.2294921875]], [[-129.90701293945312, -107.2294921875], [-149.8428955078125, -104.765380859375], [-160.93939208984375, -85.71453857421875], [-141.10739135742188, -90.268310546875]], [[-141.10739135742188, -90.268310546875], [-160.93939208984375, -85.71453857421875], [-169.9687042236328, -65.654052734375], [-150.55111694335938, -72.2783203125]], [[-150.55111694335938, -72.2783203125], [-169.9687042236328, -65.654052734375], [-176.76136779785156, -44.7684326171875], [-158.132568359375, -53.44891357421875]], [[-158.132568359375, -53.44891357421875], [-176.76136779785156, -44.7684326171875], [-181.14791870117188, -23.24176025390625], [-163.74612426757812, -33.96923828125]], [[-163.74612426757812, -33.96923828125], [-181.14791870117188, -23.24176025390625], [-182.95889282226562, -1.2586669921875], [-167.28623962402344, -14.02874755859375]], [[-167.28623962402344, -14.02874755859375], [-182.95889282226562, -1.2586669921875], [-182.5933837890625, 16.008026123046875], [-168.647216796875, 6.183502197265625]], [[20.85786247253418, -129.0084228515625], [2.758302688598633, -126.6920166015625], [-14.934160232543945, -122.283935546875], [-31.963991165161133, -115.79150390625], [-34.38192643191698, -114.50543212890625], [97.56173832535929, -114.50543212890625], [92.21580505371094, -117.21136474609375], [75.04348754882812, -123.334716796875], [57.256011962890625, -127.3370361328125], [39.10895538330078, -129.2259521484375]], [[-42.33342320185258, -110.276123046875], [9.347914695739746, -113.25213623046875], [24.75494956970215, -114.50543212890625], [-34.38192643191698, -114.50543212890625]], [[9.347914695739746, -113.25213623046875], [-42.33342320185258, -110.276123046875], [-48.07560348510742, -107.221923828125], [-5.790348052978516, -110.276123046875]], [[-5.790348052978516, -110.276123046875], [-48.07560348510742, -107.221923828125], [-59.58073234159821, -99.0274658203125], [-20.46753692626953, -105.54534912109375]], [[-20.46753692626953, -105.54534912109375], [-59.58073234159821, -99.0274658203125], [-63.01346969604492, -96.58251953125], [-34.491336822509766, -99.0274658203125]], [[-34.491336822509766, -99.0274658203125], [-63.01346969604492, -96.58251953125], [-73.4529037475586, -87.30511474609375], [-47.669456481933594, -90.69049072265625]], [[40.23844909667969, -114.068359375], [98.42523424628395, -114.068359375], [97.56173832535929, -114.50543212890625], [24.75494956970215, -114.50543212890625]], [[55.60609817504883, -111.9730224609375], [102.56485370799929, -111.9730224609375], [98.42523424628395, -114.068359375], [40.23844909667969, -114.068359375]], [[70.66561126708984, -108.251708984375], [109.58322450032607, -108.251708984375], [108.51744079589844, -108.96002197265625], [102.56485370799929, -111.9730224609375], [55.60609817504883, -111.9730224609375]], [[85.22465515136719, -102.93646240234375], [117.58096460373665, -102.93646240234375], [109.58322450032607, -108.251708984375], [70.66561126708984, -108.251708984375]], [[99.09095001220703, -96.05963134765625], [126.8957166267913, -96.05963134765625], [123.25041961669922, -99.1685791015625], [117.58096460373665, -102.93646240234375], [85.22465515136719, -102.93646240234375]], [[110.65776062011719, -89.107177734375], [135.04759320221933, -89.107177734375], [126.8957166267913, -96.05963134765625], [99.09095001220703, -96.05963134765625]], [[121.5147476196289, -81.0728759765625], [142.86358868312897, -81.0728759765625], [136.6353302001953, -87.7530517578125], [135.04759320221933, -89.107177734375], [110.65776062011719, -89.107177734375]], [[131.5780029296875, -72.05047607421875], [150.7445940461768, -72.05047607421875], [148.61412048339844, -74.90509033203125], [142.86358868312897, -81.0728759765625], [121.5147476196289, -81.0728759765625]], [[140.76370239257812, -62.13446044921875], [158.14517683221962, -62.13446044921875], [150.7445940461768, -72.05047607421875], [131.5780029296875, -72.05047607421875]], [[148.98794555664062, -51.4188232421875], [164.71153716280574, -51.4188232421875], [159.1287841796875, -60.8165283203125], [158.14517683221962, -62.13446044921875], [140.76370239257812, -62.13446044921875]], [[156.16690063476562, -39.997802734375], [170.7540934362217, -39.997802734375], [168.1212615966797, -45.6790771484375], [164.71153716280574, -51.4188232421875], [148.98794555664062, -51.4188232421875]], [[162.21665954589844, -27.965545654296875], [176.12926505214588, -27.965545654296875], [175.53350830078125, -29.68450927734375], [170.7540934362217, -39.997802734375], [156.16690063476562, -39.997802734375]], [[167.05337524414062, -15.416290283203125], [180.4785738517562, -15.416290283203125], [176.12926505214588, -27.965545654296875], [162.21665954589844, -27.965545654296875]], [[170.5931854248047, -2.444061279296875], [183.82561578191056, -2.444061279296875], [181.3074951171875, -13.024566650390625], [180.4785738517562, -15.416290283203125], [167.05337524414062, -15.416290283203125]], [[172.75221252441406, 10.8568115234375], [186.285398621504, 10.8568115234375], [185.38519287109375, 4.10888671875], [183.82561578191056, -2.444061279296875], [170.5931854248047, -2.444061279296875]], [[-47.669456481933594, -90.69049072265625], [-73.4529037475586, -87.30511474609375], [-82.76399993896484, -76.95416259765625], [-60.20840835571289, -80.1856689453125]], [[-60.20840835571289, -80.1856689453125], [-82.76399993896484, -76.95416259765625], [-90.88841247558594, -65.67120361328125], [-70.93910217285156, -68.0150146484375]], [[-70.93910217285156, -68.0150146484375], [-90.88841247558594, -65.67120361328125], [-97.7677993774414, -53.59832763671875], [-79.81768035888672, -54.4615478515625]], [[-79.81768035888672, -54.4615478515625], [-97.7677993774414, -53.59832763671875], [-103.34381103515625, -40.87725830078125], [-107.55812072753906, -27.64996337890625], [-86.80030059814453, -39.808349609375]], [[-86.80030059814453, -39.808349609375], [-107.55812072753906, -27.64996337890625], [-110.35237884521484, -14.05828857421875], [-91.84312438964844, -24.338623046875]], [[-91.84312438964844, -24.338623046875], [-110.35237884521484, -14.05828857421875], [-111.66824340820312, -0.244140625], [-94.90229034423828, -8.3353271484375]], [[-94.90229034423828, -8.3353271484375], [-111.66824340820312, -0.244140625], [-111.4473648071289, 13.650726318359375], [-95.93394470214844, 7.918426513671875]], [[-95.93394470214844, 7.918426513671875], [-111.4473648071289, 13.650726318359375], [-109.63142395019531, 27.484344482421875], [-94.89425659179688, 24.139495849609375]], [[-94.89425659179688, 24.139495849609375], [-109.63142395019531, 27.484344482421875], [-106.64192962646484, 40.961181640625], [-91.73934173583984, 40.044891357421875]], [[16.080886840820312, -57.40972900390625], [10.74910831451416, -56.1202392578125], [5.474283218383789, -54.44970703125], [0.30472564697265625, -52.40313720703125], [-4.71124267578125, -49.9864501953125], [-9.52530288696289, -47.204833984375], [-14.08913516998291, -44.0640869140625], [-14.468185485786673, -43.7535400390625], [76.41600291341649, -43.7535400390625], [69.07686614990234, -48.3653564453125], [59.147705078125, -53.0511474609375], [48.755062103271484, -56.42706298828125], [38.02739715576172, -58.36444091796875], [27.093183517456055, -58.73480224609375]], [[-17.79321962394579, -41.0294189453125], [20.533288955688477, -42.9549560546875], [28.427330017089844, -43.7535400390625], [-14.468185485786673, -43.7535400390625]], [[20.533288955688477, -42.9549560546875], [-17.79321962394579, -41.0294189453125], [-18.354419708251953, -40.56964111328125], [12.800808906555176, -41.0294189453125]], [[12.800808906555176, -41.0294189453125], [-18.354419708251953, -40.56964111328125], [-21.918521505504977, -37.07440185546875], [5.33779764175415, -37.91168212890625]], [[36.375030517578125, -43.4913330078125], [76.8332730502092, -43.4913330078125], [76.41600291341649, -43.7535400390625], [28.427330017089844, -43.7535400390625]], [[44.26848602294922, -42.23388671875], [78.74290122907449, -42.23388671875], [78.4140625, -42.49798583984375], [76.8332730502092, -43.4913330078125], [36.375030517578125, -43.4913330078125]], [[51.99979019165039, -40.04705810546875], [81.46579534139474, -40.04705810546875], [78.74290122907449, -42.23388671875], [44.26848602294922, -42.23388671875]], [[59.4610481262207, -36.99652099609375], [85.26412205254398, -36.99652099609375], [81.46579534139474, -40.04705810546875], [51.99979019165039, -40.04705810546875]], [[66.54435729980469, -33.14801025390625], [89.43661929750823, -33.14801025390625], [87.03082275390625, -35.57763671875], [85.26412205254398, -36.99652099609375], [59.4610481262207, -36.99652099609375]], [[73.14178466796875, -28.56732177734375], [93.97238010835379, -28.56732177734375], [89.43661929750823, -33.14801025390625], [66.54435729980469, -33.14801025390625]], [[79.14546966552734, -23.3201904296875], [98.26636174427166, -23.3201904296875], [94.79869842529297, -27.732818603515625], [93.97238010835379, -28.56732177734375], [73.14178466796875, -28.56732177734375]], [[5.33779764175415, -37.91168212890625], [-21.918521505504977, -37.07440185546875], [-22.27284049987793, -36.7269287109375], [3.4283790588378906, -37.07440185546875]], [[3.4283790588378906, -37.07440185546875], [-22.27284049987793, -36.7269287109375], [-23.891161525149002, -34.804443359375], [1.6902555227279663, -36.02325439453125]], [[1.6902555227279663, -36.02325439453125], [-23.891161525149002, -34.804443359375], [-25.01922859070401, -33.46435546875], [0.08587193489074707, -34.804443359375]], [[0.08587193489074707, -34.804443359375], [-25.01922859070401, -33.46435546875], [-25.796072006225586, -32.54150390625], [-1.4223215579986572, -33.46435546875]], [[-1.4223215579986572, -33.46435546875], [-25.796072006225586, -32.54150390625], [-27.11439811531094, -30.60552978515625], [-2.8718788623809814, -32.04925537109375]], [[-2.8718788623809814, -32.04925537109375], [-27.11439811531094, -30.60552978515625], [-28.875802993774414, -28.018890380859375], [-27.566905975341797, -26.5489501953125], [-26.006587982177734, -25.3736572265625], [-24.245515823364258, -24.483612060546875], [-22.334386825561523, -23.8697509765625], [-20.323869705200195, -23.52276611328125], [-18.2646541595459, -23.4334716796875], [-16.207422256469727, -23.59271240234375], [-14.202852249145508, -23.9912109375], [-12.301629066467285, -24.619720458984375], [-10.55443286895752, -25.469146728515625], [-8.83477783203125, -26.56475830078125], [-7.24424934387207, -27.816986083984375], [-5.7452898025512695, -29.17926025390625], [-4.300351142883301, -30.60552978515625]], [[85.60779571533203, -16.4735107421875], [103.18823355299592, -16.4735107421875], [101.58917236328125, -19.091888427734375], [98.26636174427166, -23.3201904296875], [79.14546966552734, -23.3201904296875]], [[91.12487030029297, -8.879302978515625], [107.70604266579578, -8.879302978515625], [107.2738265991211, -9.7835693359375], [103.18823355299592, -16.4735107421875], [85.60779571533203, -16.4735107421875]], [[95.66145324707031, -0.6693115234375], [111.6302074708026, -0.6693115234375], [107.70604266579578, -8.879302978515625], [91.12487030029297, -8.879302978515625]], [[99.1823959350586, 8.024383544921875], [114.55552107462728, 8.024383544921875], [111.9061279296875, -0.092041015625], [111.6302074708026, -0.6693115234375], [95.66145324707031, -0.6693115234375]], [[101.65249633789062, 17.07000732421875], [116.5721778006858, 17.07000732421875], [115.21315002441406, 10.039031982421875], [114.55552107462728, 8.024383544921875], [99.1823959350586, 8.024383544921875]], [[103.03656005859375, 26.3355712890625], [117.65217592043888, 26.3355712890625], [117.23052978515625, 20.47601318359375], [116.5721778006858, 17.07000732421875], [101.65249633789062, 17.07000732421875]], [[103.29943084716797, 35.68914794921875], [117.79718731810568, 35.68914794921875], [117.99392700195312, 31.0848388671875], [117.65217592043888, 26.3355712890625], [103.03656005859375, 26.3355712890625]], [[102.40589904785156, 44.998809814453125], [117.03192563209963, 44.998809814453125], [117.53898620605469, 41.731842041015625], [117.79718731810568, 35.68914794921875], [103.29943084716797, 35.68914794921875]], [[100.32079315185547, 54.1326904296875], [115.40234550720255, 54.1326904296875], [115.90133666992188, 52.28314208984375], [117.03192563209963, 44.998809814453125], [102.40589904785156, 44.998809814453125]], [[97.00892639160156, 62.95880126953125], [112.97816661930962, 62.95880126953125], [113.11660766601562, 62.604949951171875], [115.40234550720255, 54.1326904296875], [100.32079315185547, 54.1326904296875]], [[-168.647216796875, 6.183502197265625], [-182.5933837890625, 16.008026123046875], [-180.84962463378906, 33.222564697265625], [-167.7235565185547, 26.47796630859375]], [[174.09365844726562, 30.9337158203125], [187.9831495685279, 30.9337158203125], [187.70849609375, 21.524322509765625], [186.285398621504, 10.8568115234375], [172.75221252441406, 10.8568115234375]], [[172.71739196777344, 50.941314697265625], [187.40686376546213, 50.941314697265625], [188.21946716308594, 39.029754638671875], [187.9831495685279, 30.9337158203125], [174.09365844726562, 30.9337158203125]], [[-167.7235565185547, 26.47796630859375], [-180.84962463378906, 33.222564697265625], [-177.74122619628906, 50.260040283203125], [-165.5875701904297, 42.625762939453125]], [[-165.5875701904297, 42.625762939453125], [-177.74122619628906, 50.260040283203125], [-173.2819366455078, 66.99493408203125], [-161.86111450195312, 58.431427001953125]], [[-161.86111450195312, 58.431427001953125], [-173.2819366455078, 66.99493408203125], [-167.4853973388672, 83.30218505859375], [-156.63345336914062, 73.79769897460938]], [[-156.63345336914062, 73.79769897460938], [-167.4853973388672, 83.30218505859375], [-160.36532592773438, 99.0565185546875], [-149.9940185546875, 88.627197265625]], [[-149.9940185546875, 88.627197265625], [-160.36532592773438, 99.0565185546875], [-151.93539428710938, 114.1326904296875], [-142.03211975097656, 102.82266235351562]], [[-142.03211975097656, 102.82266235351562], [-151.93539428710938, 114.1326904296875], [-142.20928955078125, 128.40542602539062], [-132.83712768554688, 116.28668212890625]], [[-132.83712768554688, 116.28668212890625], [-142.20928955078125, 128.40542602539062], [-132.1231292365946, 140.6314697265625], [-122.49836730957031, 128.922119140625]], [[-122.49836730957031, 128.922119140625], [-132.1231292365946, 140.6314697265625], [-131.20069885253906, 141.74960327148438], [-111.105224609375, 140.6314697265625]], [[-111.105224609375, 140.6314697265625], [-131.20069885253906, 141.74960327148438], [-118.92338555585833, 154.03985595703125], [-98.74700927734375, 151.31756591796875]], [[-98.74700927734375, 151.31756591796875], [-118.92338555585833, 154.03985595703125], [-94.98068835193737, 154.03985595703125]], [[-91.73934173583984, 40.044891357421875], [-106.64192962646484, 40.961181640625], [-102.25096893310547, 54.093902587890625], [-96.99297836955397, 65.71539306640625], [-86.42540740966797, 55.35137939453125]], [[168.77566528320312, 70.6102294921875], [184.49676813924987, 70.6102294921875], [187.06997680664062, 55.87957763671875], [187.40686376546213, 50.941314697265625], [172.71739196777344, 50.941314697265625]], [[162.4208526611328, 89.67071533203125], [179.2286979356434, 89.67071533203125], [179.57838439941406, 88.78121948242188], [184.1640167236328, 72.51510620117188], [184.49676813924987, 70.6102294921875], [168.77566528320312, 70.6102294921875]], [[153.80526733398438, 107.853271484375], [171.68410740348398, 107.853271484375], [173.389892578125, 104.52285766601562], [179.2286979356434, 89.67071533203125], [162.4208526611328, 89.67071533203125]], [[143.08128356933594, 124.88845825195312], [162.25931908699442, 124.88845825195312], [165.67538452148438, 119.5848388671875], [171.68410740348398, 107.853271484375], [153.80526733398438, 107.853271484375]], [[130.40121459960938, 140.50653076171875], [151.1831914210874, 140.50653076171875], [156.51161193847656, 133.81207275390625], [162.25931908699442, 124.88845825195312], [143.08128356933594, 124.88845825195312]], [[115.91741943359375, 154.43804931640625], [138.74601481290358, 154.43804931640625], [145.97537231445312, 147.04946899414062], [151.1831914210874, 140.50653076171875], [130.40121459960938, 140.50653076171875]], [[99.78219604492188, 166.4134521484375], [125.35045053135009, 166.4134521484375], [134.1435546875, 159.14187622070312], [138.74601481290358, 154.43804931640625], [115.91741943359375, 154.43804931640625]], [[82.14791107177734, 176.16314697265625], [111.62489563093311, 176.16314697265625], [121.09285736083984, 169.934326171875], [125.35045053135009, 166.4134521484375], [99.78219604492188, 166.4134521484375]], [[-86.42540740966797, 55.35137939453125], [-96.99297836955397, 65.71539306640625], [-96.53167724609375, 66.7349853515625], [-81.53887176513672, 65.71539306640625]], [[-81.53887176513672, 65.71539306640625], [-96.53167724609375, 66.7349853515625], [-89.55731201171875, 78.73660278320312], [-75.496337890625, 75.41888427734375]], [[-75.496337890625, 75.41888427734375], [-89.55731201171875, 78.73660278320312], [-81.40103149414062, 89.95111083984375], [-68.40731048583984, 84.3787841796875]], [[-68.40731048583984, 84.3787841796875], [-81.40103149414062, 89.95111083984375], [-72.58283126321481, 99.73504638671875], [-60.381317138671875, 92.51190185546875]], [[-60.381317138671875, 92.51190185546875], [-72.58283126321481, 99.73504638671875], [-72.13606262207031, 100.23074340820312], [-51.527870178222656, 99.73504638671875]], [[-51.527870178222656, 99.73504638671875], [-72.13606262207031, 100.23074340820312], [-61.835601806640625, 109.42779541015625], [-41.95648956298828, 105.9649658203125]], [[-41.95648956298828, 105.9649658203125], [-61.835601806640625, 109.42779541015625], [-53.79877924242567, 115.11270141601562], [-31.77667808532715, 111.11865234375]], [[-31.77667808532715, 111.11865234375], [-53.79877924242567, 115.11270141601562], [-50.57284164428711, 117.39459228515625], [-21.097965240478516, 115.11270141601562]], [[-21.097965240478516, 115.11270141601562], [-50.57284164428711, 117.39459228515625], [-47.07778462664281, 119.28964233398438], [-10.02985954284668, 117.8641357421875]], [[-10.02985954284668, 117.8641357421875], [-47.07778462664281, 119.28964233398438], [-46.64620021497564, 119.52365112304688], [1.3181166648864746, 119.28964233398438]], [[91.82200622558594, 73.73358154296875], [108.60551904095675, 73.73358154296875], [109.22047424316406, 72.5633544921875], [112.97816661930962, 62.95880126953125], [97.00892639160156, 62.95880126953125]], [[85.18205261230469, 83.52688598632812], [103.22577812063805, 83.52688598632812], [104.24851989746094, 82.02471923828125], [108.60551904095675, 73.73358154296875], [91.82200622558594, 73.73358154296875]], [[77.26873779296875, 92.2784423828125], [97.0349418195053, 92.2784423828125], [98.23646545410156, 90.85501098632812], [103.22577812063805, 83.52688598632812], [85.18205261230469, 83.52688598632812]], [[68.26178741455078, 99.92764282226562], [90.57822382349481, 99.92764282226562], [97.0349418195053, 92.2784423828125], [77.26873779296875, 92.2784423828125]], [[58.340919494628906, 106.41415405273438], [83.77242115344117, 106.41415405273438], [89.27932739257812, 101.4664306640625], [90.57822382349481, 99.92764282226562], [68.26178741455078, 99.92764282226562]], [[47.68586730957031, 111.67742919921875], [77.56930438159624, 111.67742919921875], [79.02140808105469, 110.6827392578125], [83.77242115344117, 106.41415405273438], [58.340919494628906, 106.41415405273438]], [[36.476341247558594, 115.65707397460938], [71.75959759728383, 115.65707397460938], [77.56930438159624, 111.67742919921875], [47.68586730957031, 111.67742919921875]], [[24.89206314086914, 118.29263305664062], [67.91206186393934, 118.29263305664062], [71.75959759728383, 115.65707397460938], [36.476341247558594, 115.65707397460938]], [[13.112751960754395, 119.52365112304688], [65.59938528136169, 119.52365112304688], [67.66618347167969, 118.4610595703125], [67.91206186393934, 118.29263305664062], [24.89206314086914, 118.29263305664062]], [[1.3181166648864746, 119.28964233398438], [-46.64620021497564, 119.52365112304688], [13.112751960754395, 119.52365112304688]], [[-38.42099380493164, 123.98342895507812], [-25.4532527923584, 129.04653930664062], [-12.114139556884766, 132.53396606445312], [1.5519838333129883, 134.28335571289062], [15.341647148132324, 134.33770751953125], [29.051372528076172, 132.73980712890625], [42.47768783569336, 129.532470703125], [55.4171142578125, 124.75860595703125], [65.59938528136169, 119.52365112304688], [-46.64620021497564, 119.52365112304688]], [[-100.21424102783203, 169.71759033203125], [-85.51312255859375, 160.88299560546875], [-94.98068835193737, 154.03985595703125], [-118.9233169555664, 154.03985595703125]], [[-85.51312255859375, 160.88299560546875], [-100.21424102783203, 169.71759033203125], [-87.63823188040341, 177.54388427734375], [-70.44490814208984, 169.98309326171875]], [[-70.44490814208984, 169.98309326171875], [-87.63823188040341, 177.54388427734375], [-79.60450744628906, 182.54342651367188], [-54.537025451660156, 177.54388427734375]], [[-54.537025451660156, 177.54388427734375], [-79.60450744628906, 182.54342651367188], [-67.84250018894451, 187.83267211914062], [-37.96284103393555, 183.51168823242188]], [[-37.96284103393555, 183.51168823242188], [-67.84250018894451, 187.83267211914062], [-62.01544823159079, 190.45303344726562], [-20.895767211914062, 187.83267211914062]], [[-20.895767211914062, 187.83267211914062], [-62.01544823159079, 190.45303344726562], [-60.08981467981226, 191.3189697265625], [-3.5091705322265625, 190.45303344726562]], [[-3.5091705322265625, 190.45303344726562], [-60.08981467981226, 191.3189697265625], [14.023551940917969, 191.3189697265625]], [[65.76456451416016, 182.85269165039062], [99.78013212237508, 182.85269165039062], [106.90019226074219, 179.27145385742188], [111.62489563093311, 176.16314697265625], [82.14791107177734, 176.16314697265625]], [[48.83381271362305, 187.57257080078125], [90.39627510439473, 187.57257080078125], [99.78013212237508, 182.85269165039062], [65.76456451416016, 182.85269165039062]], [[31.52900505065918, 190.37680053710938], [84.67952877840162, 190.37680053710938], [85.12433624267578, 190.2242431640625], [90.39627510439473, 187.57257080078125], [48.83381271362305, 187.57257080078125]], [[14.023551940917969, 191.3189697265625], [81.93247119797832, 191.3189697265625], [84.67952877840162, 190.37680053710938], [31.52900505065918, 190.37680053710938]], [[-57.48405075073242, 192.49075317382812], [-34.242889404296875, 199.53265380859375], [-10.270980834960938, 203.6424560546875], [14.041683197021484, 204.79327392578125], [38.30510711669922, 202.9583740234375], [62.129329681396484, 198.11093139648438], [81.93247119797832, 191.3189697265625], [-60.08981467981226, 191.3189697265625]]] \ No newline at end of file diff --git a/examples/17-concave-phys-objects/concave2convex.py b/examples/17-concave-phys-objects/concave2convex.py index 810ee7d8..e2b03c3f 100644 --- a/examples/17-concave-phys-objects/concave2convex.py +++ b/examples/17-concave-phys-objects/concave2convex.py @@ -1,33 +1,18 @@ +from itertools import cycle import json import os import signal from kivy.logger import Logger from kivy.vector import Vector +from Polygon import Polygon +#from debugdraw import gv -def bisect_iter(ilist): - if len(ilist) <= 2: - for x in ilist: - yield x - return - - mid = int(len(ilist)/2) - yield ilist[mid] - - for x in bisect_iter(ilist[:mid]): - yield x - - for x in bisect_iter(ilist[mid + 1:]): - yield x - -def uniq(plist): - ret = [] - for x in plist: - if x not in ret: - ret.append(x) - return ret - +ZERO = 0.0001 +def azero(f): + """ almost zero """ + return abs(f) < ZERO def cross(v1, v2): return v1.x*v2.y - v1.y*v2.x @@ -50,111 +35,109 @@ def fix_winding(verts): else: return verts[::-1] +def simplify_poly(poly): + """ sometimes, poly IS convex, but cymunk/chipmunk claims that is not. It's + when eg. v1 x v2 are negative (then clockwise), but so small that chipmunk + probably calculates it differently, treat them as + counterclockwise. In such case, such segments should be joined into + one. + """ + + simp_needed = True + verts = poly[:] + while simp_needed: + simp_needed = False + for v1,v2,v3 in zip(verts, verts[1:] + verts[:1], verts[2:] + verts[:2]): + vec1 = Vector(v2) - Vector(v1) + vec2 = Vector(v3) - Vector(v2) + + v1x2 = cross(vec1, vec2) + if abs(v1x2) < ZERO: #almost parallel, simplify to to one + simp_needed = True + verts.remove(v2) #put middle vertex in trash + continue + + return verts + + + + def is_convex(verts): for v1,v2,v3 in zip(verts, verts[1:] + verts[:1], verts[2:] + verts[:2]): vec1 = Vector(v2) - Vector(v1) vec2 = Vector(v3) - Vector(v2) cr = cross(vec1, vec2) - if cr == 0 and vec1.dot(vec2) < 0: + if azero(cr) and vec1.dot(vec2) < 0: return False - if cross(vec1, vec2) > 0: + if cross(vec1, vec2) > - ZERO: return False return True -def split_path(path, vertsplit): - left = path[:vertsplit] - right = path[vertsplit-1:] + [path[0]] - - if hasattr(split_path, 'debug'): - gnuplot_verts(path, left, right) - return left, right - -def point_in_poly(verts, point): - #vectors of path - vertpairs = zip(verts, verts[1:] + verts[:1]) - - side = None - for vert1, vert2 in vertpairs: - vec1 = Vector(vert2) - Vector(vert1) - vec2 = Vector(point) - Vector(vert1) - vec1xvec2 = cross(vec1, vec2) - if vec1xvec2 == 0: +def add_polys(ppoly, triangle): + if not ppoly: + return triangle + poly = ppoly[:] + adjacent = False + for v1,v2,v3 in zip(triangle, triangle[1:] + triangle[:1], triangle[2:] + triangle[:2]): + if not (v1 in poly and v2 in poly): continue - - if side is None: - side = vec1xvec2 - - if side < 0 and vec1xvec2 > 0: - return False - - if side > 0 and vec1xvec2 < 0: - return False - - return True - - - -def intersects_with_remaining(path, remaining): - - for rv in bisect_iter(remaining[1:-1]): - if point_in_poly(path, rv): - return True - return False - - -def signaltrace(signal, frame): - import pudb;pudb.set_trace()#TODO:FIXME:DEBUG:remove this breakpoint - -def concave2convex(path, desired_area=0.1, min_area=0.01): - - path = uniq(path) - path_area = area(path) - - desired_area *= path_area - min_area *= path_area - - path = fix_winding(path) - - rotate_cnt = 0 - while True: - lgpiece = None - lgremain = None - lgarea = 0 - if is_convex(path): - yield path - return - for splitvert in range(3, len(path)): - piece, remaining = split_path(path, splitvert) - piece_is_convex = is_convex(piece) - if piece_is_convex and is_convex(remaining): - yield piece - yield remaining - return - if not piece_is_convex or intersects_with_remaining(piece, remaining): - if not lgpiece or not lgremain or lgarea > -desired_area: - #rotate path - rotate_cnt+=1 - Logger.debug("rotate path no %s", rotate_cnt) - path = path[1:] + path[:1] - if rotate_cnt >= len(path): - desired_area /= 2 - Logger.debug("desired area is now %s", desired_area) - if desired_area <= min_area: - Logger.debug("which is below minimum, exiting") - return - rotate_cnt = 0 - break - yield lgpiece - path = lgremain - break - lgpiece = piece - lgremain = remaining - lgarea = area(lgpiece) - -def cached_c2c(path, cache_dir=".convexpolys", **kwargs): + adjacent = True + v1idx = poly.index(v1) + if v1idx + 1 < len(poly) and poly[v1idx + 1] == v2: + poly[v1idx + 1:v1idx + 1] = [v3] + break + elif v1idx > 0 and poly[v1idx -1] == v2: + poly[v1idx: v1idx] = [v3] + break + else: + return None + if not adjacent: + return None + poly = simplify_poly(poly) + return poly + +def calc_triangles(poly): + opoly = Polygon(poly) + for trisentry in opoly.triStrip(): + for triangle in zip(trisentry[:-2], trisentry[1:-1], trisentry[2:]): + yield fix_winding(list(triangle)) + + + +def merge_triangles(poly, min_area=None): + #if is concave, do nothing, just return poly + if is_convex(poly): + yield poly + return + triangles = list(calc_triangles(poly)) + #gv(triangles) + remaining = [] + while triangles: + piece = [] + for i, triangle in enumerate(triangles): + if not is_convex(triangle): + continue + print "processing triangle#%s"%i + cand = add_polys(piece, triangle) + + if cand != None and is_convex(cand): + piece = cand + continue + remaining.append(triangle) + #gv(triangles, [piece], [triangle], [triangle, piece], remaining) + assert piece + assert is_convex(piece) + assert area(piece) != 0 + yield fix_winding(piece) + piece = [] + triangles = remaining + remaining = [] + + +def cached_mtr(path, cache_dir=".convexpolys", **kwargs): pathhash = str(hash(tuple(path + kwargs.items()))) fname = os.path.join(cache_dir, pathhash) try: @@ -167,21 +150,12 @@ def cached_c2c(path, cache_dir=".convexpolys", **kwargs): if not os.path.isdir(cache_dir): raise fp = open(fname, "w") - ret = list(concave2convex(path, **kwargs)) + ret = list(merge_triangles(path, **kwargs)) json.dump(ret, fp) fp.close() return ret -if __name__ == '__main__': - from debugdraw import gnuplot_verts - - for x in concave2convex([(0,0), (0,2), (1,1), (2,2), (2,0), (1, 0.5)]): - gnuplot_verts(x) - - - - diff --git a/examples/17-concave-phys-objects/debugdraw.py b/examples/17-concave-phys-objects/debugdraw.py index 886713f7..44fc0cae 100644 --- a/examples/17-concave-phys-objects/debugdraw.py +++ b/examples/17-concave-phys-objects/debugdraw.py @@ -3,44 +3,37 @@ import os -def gnuplot_verts(*vss, **kwargs): +def gv(*groups, **kwargs): pdf = kwargs.get("pdf", True) single = kwargs.get("single", False) closed = kwargs.get("closed", True) f = open("/tmp/ee.plt", "w") minr, maxr = 999999, -9999999 - for path in vss: - for vert in path: - for coord in vert: - minr = min(minr, coord) - maxr = max(maxr, coord) - - numplots = len(vss) + for group in groups: + for path in group: + for vert in path: + for coord in vert: + minr = min(minr, coord) + maxr = max(maxr, coord) + + numplots = len(groups) inrow = int(ceil(sqrt(numplots))) numrows = int(ceil(float(numplots)/inrow)) if pdf: f.write('set terminal pdfcairo font "arial, 9" size 30cm,30cm \n') f.write('set output "/tmp/ee.pdf"\n') - if not single: - f.write("set multiplot layout %s, %s\n"%(numrows, inrow)) + f.write("set multiplot layout %s, %s\n"%(numrows, inrow)) f.write("set size ratio -1\n") - if single: + f.write("set xrange[%s:%s]\n"%(minr-1, maxr+1)) + f.write("set yrange[%s:%s]\n"%(minr-1, maxr+1)) + for group in groups: f.write("plot '-' u 1:2:3:4 w vectors\n") - for vs in vss: - #f.write("set xrange[%s:%s]\n"%(minr-1, maxr+1)) - #f.write("set yrange[%s:%s]\n"%(minr-1, maxr+1)) - if not single: - f.write("plot '-' u 1:2:3:4 w vectors\n") - - for (fx, fy),(tx, ty) in (zip(vs, vs[1:] + vs[:1]) if closed else zip(vs[:-1], vs[1:])): - f.write("%s %s %s %s\n"%(fx, fy, (tx-fx), (ty-fy))) - - if not single: - f.write("e\n") - if single: + for vs in group: + for (fx, fy),(tx, ty) in (zip(vs, vs[1:] + vs[:1]) if closed else zip(vs[:-1], vs[1:])): + f.write("%s %s %s %s\n"%(fx, fy, (tx-fx), (ty-fy))) f.write("e\n") f.close() @@ -48,5 +41,10 @@ def gnuplot_verts(*vss, **kwargs): if __name__ == '__main__': - gnuplot_verts([(0, 0), (0,1), (1,1), (1, 0)], - [(1,1), (2,2), (3,2), (4,0)]) + gv([[(-85.18263244628906, -194.4100341796875), (48.45586013793945, -193.8280029296875), (45.539608954794595, -194.4100341796875), (1.3924713134765625, -203.22100830078125)], + [(-80, -80), (-80, 80), (80, 80), (80, -80)]], + [ + [(1,2), (2,3), (3,4), (4,5)], + [] + ] + , closed=False) diff --git a/examples/17-concave-phys-objects/main.py b/examples/17-concave-phys-objects/main.py index a6f3b5c5..fa2e5d81 100644 --- a/examples/17-concave-phys-objects/main.py +++ b/examples/17-concave-phys-objects/main.py @@ -1,6 +1,7 @@ from functools import partial from os.path import dirname, join, abspath from random import randint, choice +import signal from math import radians, pi, sin, cos from kivy.app import App @@ -21,8 +22,8 @@ from kivent_cymunk.interaction import CymunkTouchSystem from kivy.properties import StringProperty, NumericProperty -from concave2convex import concave2convex, cached_c2c -from debugdraw import gnuplot_verts +from concave2convex import merge_triangles, cached_mtr +from debugdraw import gv texture_manager.load_atlas(join(dirname(dirname(abspath(__file__))), 'assets', 'background_objects.atlas')) @@ -46,6 +47,7 @@ def destroy_created_entity(self, ent_id, dt): self.app.count -= 1 def draw_some_stuff(self): + self.gameworld.clear_entities() self.load_svg('objects.svg', self.gameworld) @@ -53,16 +55,22 @@ def load_svg(self, fname, gameworld): mm = gameworld.model_manager data = mm.get_model_info_for_svg(fname) + posvel = { + 'spiral': ((200, 200), (0, 0)), + 'ball': ((500, 30), (-200, 0)) + } + for info in data['model_info']: - - pos = (randint(0, 600), randint(0, 400)) + + pos, vel = posvel[info.element_id] Logger.debug("adding object with title/element_id=%s/%s and desc=%s", info.title, info.element_id, info.description) model_name = mm.load_model_from_model_info(info, data['svg_name']) shapeno = 0 shapes = [] - for poly in cached_c2c(info.path_vertices, min_area=0.00001): + for poly in cached_mtr(info.path_vertices): + #for poly in merge_triangles(info.path_vertices): shape = { 'shape_type': 'poly', @@ -80,13 +88,14 @@ def load_svg(self, fname, gameworld): shapeno += 1 shapes.append(shape) - gnuplot_verts(*[x['shape_info']['vertices'] for x in shapes], single=True, pdf=False) - + #shapepolys = [x['shape_info']['vertices'] for x in shapes] + #gv(shapepolys, pdf=False) + physics = { 'main_shape': 'poly', - 'velocity': (0, 0), + 'velocity': vel, 'position': pos, 'angle': 0, 'angular_velocity': radians(0), @@ -133,6 +142,5 @@ def update_fps(self,dt): class YourAppNameApp(App): count = NumericProperty(0) - if __name__ == '__main__': YourAppNameApp().run() diff --git a/examples/17-concave-phys-objects/objects.svg b/examples/17-concave-phys-objects/objects.svg index 9b1692da..ca25679b 100644 --- a/examples/17-concave-phys-objects/objects.svg +++ b/examples/17-concave-phys-objects/objects.svg @@ -30,9 +30,9 @@ inkscape:window-height="1065" id="namedview8" showgrid="false" - inkscape:zoom="0.9833334" - inkscape:cx="-268.99043" - inkscape:cy="238.08568" + inkscape:zoom="1.3906434" + inkscape:cx="298.82756" + inkscape:cy="27.37035" inkscape:window-x="1916" inkscape:window-y="-3" inkscape:window-maximized="1" @@ -97,8 +97,18 @@ + From 148477fd4d8dbc2cab883c20e0c4152b7ce0c874 Mon Sep 17 00:00:00 2001 From: maho Date: Wed, 17 May 2017 15:15:42 +0200 Subject: [PATCH 5/5] - FIXED, FIXED, example is ok --- .../.convexpolys/-5187266973737743100 | 1 - .../.convexpolys/1136951465492135774 | 1 - examples/17-concave-phys-objects/main.py | 22 +++++++++++-------- examples/17-concave-phys-objects/objects.svg | 17 +++++--------- 4 files changed, 19 insertions(+), 22 deletions(-) delete mode 100644 examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 delete mode 100644 examples/17-concave-phys-objects/.convexpolys/1136951465492135774 diff --git a/examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 b/examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 deleted file mode 100644 index 13c0788a..00000000 --- a/examples/17-concave-phys-objects/.convexpolys/-5187266973737743100 +++ /dev/null @@ -1 +0,0 @@ -[[[13.899310111999512, 84.99319458007812], [13.347455978393555, 85.22177124023438], [12.873567581176758, 85.58541870117188], [12.509940147399902, 86.05929565429688], [12.281354904174805, 86.61114501953125], [12.203388214111328, 87.203369140625], [12.281354904174805, 87.79559326171875], [12.509940147399902, 88.34744262695312], [12.873567581176758, 88.82131958007812], [13.347455978393555, 89.18496704101562], [13.899310111999512, 89.41354370117188], [14.491523742675781, 89.49151611328125], [15.083736419677734, 89.41354370117188], [15.635591506958008, 89.18496704101562], [16.109479904174805, 88.82131958007812], [16.473106384277344, 88.34744262695312], [16.701692581176758, 87.79559326171875], [16.779659271240234, 87.203369140625], [16.701692581176758, 86.61114501953125], [16.473106384277344, 86.05929565429688], [16.109479904174805, 85.58541870117188], [15.635591506958008, 85.22177124023438], [15.083736419677734, 84.99319458007812], [14.491523742675781, 84.91522216796875]]] \ No newline at end of file diff --git a/examples/17-concave-phys-objects/.convexpolys/1136951465492135774 b/examples/17-concave-phys-objects/.convexpolys/1136951465492135774 deleted file mode 100644 index d07441c9..00000000 --- a/examples/17-concave-phys-objects/.convexpolys/1136951465492135774 +++ /dev/null @@ -1 +0,0 @@ -[[[6.367440223693848, -200.77423095703125], [-2.4026951789855957, -199.735107421875], [-11.125282287597656, -198.3558349609375], [-19.78165054321289, -196.627685546875], [-28.353118896484375, -194.5413818359375], [-36.82102584838867, -192.08795166015625], [-45.16668701171875, -189.25848388671875], [-53.37143325805664, -186.04388427734375], [2.3814239501953125, -186.11163330078125], [13.111351013183594, -187.2626953125], [14.468262672424316, -188.17547607421875], [15.575579643249512, -189.34173583984375], [16.430946350097656, -190.70843505859375], [17.032014846801758, -192.22344970703125], [17.37643051147461, -193.833984375], [17.461843490600586, -195.487548828125], [17.285905838012695, -197.1318359375], [16.846261978149414, -198.714111328125], [16.140560150146484, -200.18182373046875], [15.166451454162598, -201.4825439453125]], [[2.3814239501953125, -186.11163330078125], [-53.37143325805664, -186.04388427734375], [-61.416587829589844, -182.43505859375], [-8.262374877929688, -184.3533935546875]], [[-8.262374877929688, -184.3533935546875], [-61.416587829589844, -182.43505859375], [-68.01629878190201, -179.0693359375], [-18.790969848632812, -182.00140380859375]], [[-18.790969848632812, -182.00140380859375], [-68.01629878190201, -179.0693359375], [-69.28348541259766, -178.423095703125], [-29.175262451171875, -179.0693359375]], [[-29.175262451171875, -179.0693359375], [-69.28348541259766, -178.423095703125], [-80.88998724890138, -171.5186767578125], [-39.38617706298828, -175.570556640625]], [[-39.38617706298828, -175.570556640625], [-80.88998724890138, -171.5186767578125], [-88.17408752441406, -167.185546875], [-49.39461898803711, -171.5186767578125]], [[-49.39461898803711, -171.5186767578125], [-88.17408752441406, -167.185546875], [-95.38882592100362, -161.80889892578125], [-59.17149353027344, -166.92681884765625]], [[-59.17149353027344, -166.92681884765625], [-95.38882592100362, -161.80889892578125], [-102.94468185992774, -156.17803955078125], [-68.68772888183594, -161.80889892578125]], [[-68.68772888183594, -161.80889892578125], [-102.94468185992774, -156.17803955078125], [-105.84479522705078, -154.01678466796875], [-77.9142074584961, -156.17803955078125]], [[-77.9142074584961, -156.17803955078125], [-105.84479522705078, -154.01678466796875], [-122.12613677978516, -139.100830078125], [-86.82188415527344, -150.0479736328125]], [[-86.82188415527344, -150.0479736328125], [-122.12613677978516, -139.100830078125], [-136.53560024143127, -122.97271728515625], [-102.65865325927734, -137.30859375]], [[-102.65865325927734, -137.30859375], [-136.53560024143127, -122.97271728515625], [-136.84866333007812, -122.622314453125], [-117.0555648803711, -122.97271728515625]], [[-117.0555648803711, -122.97271728515625], [-136.84866333007812, -122.622314453125], [-149.8428955078125, -104.765380859375], [-129.90701293945312, -107.2294921875]], [[-129.90701293945312, -107.2294921875], [-149.8428955078125, -104.765380859375], [-160.93939208984375, -85.71453857421875], [-141.10739135742188, -90.268310546875]], [[-141.10739135742188, -90.268310546875], [-160.93939208984375, -85.71453857421875], [-169.9687042236328, -65.654052734375], [-150.55111694335938, -72.2783203125]], [[-150.55111694335938, -72.2783203125], [-169.9687042236328, -65.654052734375], [-176.76136779785156, -44.7684326171875], [-158.132568359375, -53.44891357421875]], [[-158.132568359375, -53.44891357421875], [-176.76136779785156, -44.7684326171875], [-181.14791870117188, -23.24176025390625], [-163.74612426757812, -33.96923828125]], [[-163.74612426757812, -33.96923828125], [-181.14791870117188, -23.24176025390625], [-182.95889282226562, -1.2586669921875], [-167.28623962402344, -14.02874755859375]], [[-167.28623962402344, -14.02874755859375], [-182.95889282226562, -1.2586669921875], [-182.5933837890625, 16.008026123046875], [-168.647216796875, 6.183502197265625]], [[20.85786247253418, -129.0084228515625], [2.758302688598633, -126.6920166015625], [-14.934160232543945, -122.283935546875], [-31.963991165161133, -115.79150390625], [-34.38192643191698, -114.50543212890625], [97.56173832535929, -114.50543212890625], [92.21580505371094, -117.21136474609375], [75.04348754882812, -123.334716796875], [57.256011962890625, -127.3370361328125], [39.10895538330078, -129.2259521484375]], [[-42.33342320185258, -110.276123046875], [9.347914695739746, -113.25213623046875], [24.75494956970215, -114.50543212890625], [-34.38192643191698, -114.50543212890625]], [[9.347914695739746, -113.25213623046875], [-42.33342320185258, -110.276123046875], [-48.07560348510742, -107.221923828125], [-5.790348052978516, -110.276123046875]], [[-5.790348052978516, -110.276123046875], [-48.07560348510742, -107.221923828125], [-59.58073234159821, -99.0274658203125], [-20.46753692626953, -105.54534912109375]], [[-20.46753692626953, -105.54534912109375], [-59.58073234159821, -99.0274658203125], [-63.01346969604492, -96.58251953125], [-34.491336822509766, -99.0274658203125]], [[-34.491336822509766, -99.0274658203125], [-63.01346969604492, -96.58251953125], [-73.4529037475586, -87.30511474609375], [-47.669456481933594, -90.69049072265625]], [[40.23844909667969, -114.068359375], [98.42523424628395, -114.068359375], [97.56173832535929, -114.50543212890625], [24.75494956970215, -114.50543212890625]], [[55.60609817504883, -111.9730224609375], [102.56485370799929, -111.9730224609375], [98.42523424628395, -114.068359375], [40.23844909667969, -114.068359375]], [[70.66561126708984, -108.251708984375], [109.58322450032607, -108.251708984375], [108.51744079589844, -108.96002197265625], [102.56485370799929, -111.9730224609375], [55.60609817504883, -111.9730224609375]], [[85.22465515136719, -102.93646240234375], [117.58096460373665, -102.93646240234375], [109.58322450032607, -108.251708984375], [70.66561126708984, -108.251708984375]], [[99.09095001220703, -96.05963134765625], [126.8957166267913, -96.05963134765625], [123.25041961669922, -99.1685791015625], [117.58096460373665, -102.93646240234375], [85.22465515136719, -102.93646240234375]], [[110.65776062011719, -89.107177734375], [135.04759320221933, -89.107177734375], [126.8957166267913, -96.05963134765625], [99.09095001220703, -96.05963134765625]], [[121.5147476196289, -81.0728759765625], [142.86358868312897, -81.0728759765625], [136.6353302001953, -87.7530517578125], [135.04759320221933, -89.107177734375], [110.65776062011719, -89.107177734375]], [[131.5780029296875, -72.05047607421875], [150.7445940461768, -72.05047607421875], [148.61412048339844, -74.90509033203125], [142.86358868312897, -81.0728759765625], [121.5147476196289, -81.0728759765625]], [[140.76370239257812, -62.13446044921875], [158.14517683221962, -62.13446044921875], [150.7445940461768, -72.05047607421875], [131.5780029296875, -72.05047607421875]], [[148.98794555664062, -51.4188232421875], [164.71153716280574, -51.4188232421875], [159.1287841796875, -60.8165283203125], [158.14517683221962, -62.13446044921875], [140.76370239257812, -62.13446044921875]], [[156.16690063476562, -39.997802734375], [170.7540934362217, -39.997802734375], [168.1212615966797, -45.6790771484375], [164.71153716280574, -51.4188232421875], [148.98794555664062, -51.4188232421875]], [[162.21665954589844, -27.965545654296875], [176.12926505214588, -27.965545654296875], [175.53350830078125, -29.68450927734375], [170.7540934362217, -39.997802734375], [156.16690063476562, -39.997802734375]], [[167.05337524414062, -15.416290283203125], [180.4785738517562, -15.416290283203125], [176.12926505214588, -27.965545654296875], [162.21665954589844, -27.965545654296875]], [[170.5931854248047, -2.444061279296875], [183.82561578191056, -2.444061279296875], [181.3074951171875, -13.024566650390625], [180.4785738517562, -15.416290283203125], [167.05337524414062, -15.416290283203125]], [[172.75221252441406, 10.8568115234375], [186.285398621504, 10.8568115234375], [185.38519287109375, 4.10888671875], [183.82561578191056, -2.444061279296875], [170.5931854248047, -2.444061279296875]], [[-47.669456481933594, -90.69049072265625], [-73.4529037475586, -87.30511474609375], [-82.76399993896484, -76.95416259765625], [-60.20840835571289, -80.1856689453125]], [[-60.20840835571289, -80.1856689453125], [-82.76399993896484, -76.95416259765625], [-90.88841247558594, -65.67120361328125], [-70.93910217285156, -68.0150146484375]], [[-70.93910217285156, -68.0150146484375], [-90.88841247558594, -65.67120361328125], [-97.7677993774414, -53.59832763671875], [-79.81768035888672, -54.4615478515625]], [[-79.81768035888672, -54.4615478515625], [-97.7677993774414, -53.59832763671875], [-103.34381103515625, -40.87725830078125], [-107.55812072753906, -27.64996337890625], [-86.80030059814453, -39.808349609375]], [[-86.80030059814453, -39.808349609375], [-107.55812072753906, -27.64996337890625], [-110.35237884521484, -14.05828857421875], [-91.84312438964844, -24.338623046875]], [[-91.84312438964844, -24.338623046875], [-110.35237884521484, -14.05828857421875], [-111.66824340820312, -0.244140625], [-94.90229034423828, -8.3353271484375]], [[-94.90229034423828, -8.3353271484375], [-111.66824340820312, -0.244140625], [-111.4473648071289, 13.650726318359375], [-95.93394470214844, 7.918426513671875]], [[-95.93394470214844, 7.918426513671875], [-111.4473648071289, 13.650726318359375], [-109.63142395019531, 27.484344482421875], [-94.89425659179688, 24.139495849609375]], [[-94.89425659179688, 24.139495849609375], [-109.63142395019531, 27.484344482421875], [-106.64192962646484, 40.961181640625], [-91.73934173583984, 40.044891357421875]], [[16.080886840820312, -57.40972900390625], [10.74910831451416, -56.1202392578125], [5.474283218383789, -54.44970703125], [0.30472564697265625, -52.40313720703125], [-4.71124267578125, -49.9864501953125], [-9.52530288696289, -47.204833984375], [-14.08913516998291, -44.0640869140625], [-14.468185485786673, -43.7535400390625], [76.41600291341649, -43.7535400390625], [69.07686614990234, -48.3653564453125], [59.147705078125, -53.0511474609375], [48.755062103271484, -56.42706298828125], [38.02739715576172, -58.36444091796875], [27.093183517456055, -58.73480224609375]], [[-17.79321962394579, -41.0294189453125], [20.533288955688477, -42.9549560546875], [28.427330017089844, -43.7535400390625], [-14.468185485786673, -43.7535400390625]], [[20.533288955688477, -42.9549560546875], [-17.79321962394579, -41.0294189453125], [-18.354419708251953, -40.56964111328125], [12.800808906555176, -41.0294189453125]], [[12.800808906555176, -41.0294189453125], [-18.354419708251953, -40.56964111328125], [-21.918521505504977, -37.07440185546875], [5.33779764175415, -37.91168212890625]], [[36.375030517578125, -43.4913330078125], [76.8332730502092, -43.4913330078125], [76.41600291341649, -43.7535400390625], [28.427330017089844, -43.7535400390625]], [[44.26848602294922, -42.23388671875], [78.74290122907449, -42.23388671875], [78.4140625, -42.49798583984375], [76.8332730502092, -43.4913330078125], [36.375030517578125, -43.4913330078125]], [[51.99979019165039, -40.04705810546875], [81.46579534139474, -40.04705810546875], [78.74290122907449, -42.23388671875], [44.26848602294922, -42.23388671875]], [[59.4610481262207, -36.99652099609375], [85.26412205254398, -36.99652099609375], [81.46579534139474, -40.04705810546875], [51.99979019165039, -40.04705810546875]], [[66.54435729980469, -33.14801025390625], [89.43661929750823, -33.14801025390625], [87.03082275390625, -35.57763671875], [85.26412205254398, -36.99652099609375], [59.4610481262207, -36.99652099609375]], [[73.14178466796875, -28.56732177734375], [93.97238010835379, -28.56732177734375], [89.43661929750823, -33.14801025390625], [66.54435729980469, -33.14801025390625]], [[79.14546966552734, -23.3201904296875], [98.26636174427166, -23.3201904296875], [94.79869842529297, -27.732818603515625], [93.97238010835379, -28.56732177734375], [73.14178466796875, -28.56732177734375]], [[5.33779764175415, -37.91168212890625], [-21.918521505504977, -37.07440185546875], [-22.27284049987793, -36.7269287109375], [3.4283790588378906, -37.07440185546875]], [[3.4283790588378906, -37.07440185546875], [-22.27284049987793, -36.7269287109375], [-23.891161525149002, -34.804443359375], [1.6902555227279663, -36.02325439453125]], [[1.6902555227279663, -36.02325439453125], [-23.891161525149002, -34.804443359375], [-25.01922859070401, -33.46435546875], [0.08587193489074707, -34.804443359375]], [[0.08587193489074707, -34.804443359375], [-25.01922859070401, -33.46435546875], [-25.796072006225586, -32.54150390625], [-1.4223215579986572, -33.46435546875]], [[-1.4223215579986572, -33.46435546875], [-25.796072006225586, -32.54150390625], [-27.11439811531094, -30.60552978515625], [-2.8718788623809814, -32.04925537109375]], [[-2.8718788623809814, -32.04925537109375], [-27.11439811531094, -30.60552978515625], [-28.875802993774414, -28.018890380859375], [-27.566905975341797, -26.5489501953125], [-26.006587982177734, -25.3736572265625], [-24.245515823364258, -24.483612060546875], [-22.334386825561523, -23.8697509765625], [-20.323869705200195, -23.52276611328125], [-18.2646541595459, -23.4334716796875], [-16.207422256469727, -23.59271240234375], [-14.202852249145508, -23.9912109375], [-12.301629066467285, -24.619720458984375], [-10.55443286895752, -25.469146728515625], [-8.83477783203125, -26.56475830078125], [-7.24424934387207, -27.816986083984375], [-5.7452898025512695, -29.17926025390625], [-4.300351142883301, -30.60552978515625]], [[85.60779571533203, -16.4735107421875], [103.18823355299592, -16.4735107421875], [101.58917236328125, -19.091888427734375], [98.26636174427166, -23.3201904296875], [79.14546966552734, -23.3201904296875]], [[91.12487030029297, -8.879302978515625], [107.70604266579578, -8.879302978515625], [107.2738265991211, -9.7835693359375], [103.18823355299592, -16.4735107421875], [85.60779571533203, -16.4735107421875]], [[95.66145324707031, -0.6693115234375], [111.6302074708026, -0.6693115234375], [107.70604266579578, -8.879302978515625], [91.12487030029297, -8.879302978515625]], [[99.1823959350586, 8.024383544921875], [114.55552107462728, 8.024383544921875], [111.9061279296875, -0.092041015625], [111.6302074708026, -0.6693115234375], [95.66145324707031, -0.6693115234375]], [[101.65249633789062, 17.07000732421875], [116.5721778006858, 17.07000732421875], [115.21315002441406, 10.039031982421875], [114.55552107462728, 8.024383544921875], [99.1823959350586, 8.024383544921875]], [[103.03656005859375, 26.3355712890625], [117.65217592043888, 26.3355712890625], [117.23052978515625, 20.47601318359375], [116.5721778006858, 17.07000732421875], [101.65249633789062, 17.07000732421875]], [[103.29943084716797, 35.68914794921875], [117.79718731810568, 35.68914794921875], [117.99392700195312, 31.0848388671875], [117.65217592043888, 26.3355712890625], [103.03656005859375, 26.3355712890625]], [[102.40589904785156, 44.998809814453125], [117.03192563209963, 44.998809814453125], [117.53898620605469, 41.731842041015625], [117.79718731810568, 35.68914794921875], [103.29943084716797, 35.68914794921875]], [[100.32079315185547, 54.1326904296875], [115.40234550720255, 54.1326904296875], [115.90133666992188, 52.28314208984375], [117.03192563209963, 44.998809814453125], [102.40589904785156, 44.998809814453125]], [[97.00892639160156, 62.95880126953125], [112.97816661930962, 62.95880126953125], [113.11660766601562, 62.604949951171875], [115.40234550720255, 54.1326904296875], [100.32079315185547, 54.1326904296875]], [[-168.647216796875, 6.183502197265625], [-182.5933837890625, 16.008026123046875], [-180.84962463378906, 33.222564697265625], [-167.7235565185547, 26.47796630859375]], [[174.09365844726562, 30.9337158203125], [187.9831495685279, 30.9337158203125], [187.70849609375, 21.524322509765625], [186.285398621504, 10.8568115234375], [172.75221252441406, 10.8568115234375]], [[172.71739196777344, 50.941314697265625], [187.40686376546213, 50.941314697265625], [188.21946716308594, 39.029754638671875], [187.9831495685279, 30.9337158203125], [174.09365844726562, 30.9337158203125]], [[-167.7235565185547, 26.47796630859375], [-180.84962463378906, 33.222564697265625], [-177.74122619628906, 50.260040283203125], [-165.5875701904297, 42.625762939453125]], [[-165.5875701904297, 42.625762939453125], [-177.74122619628906, 50.260040283203125], [-173.2819366455078, 66.99493408203125], [-161.86111450195312, 58.431427001953125]], [[-161.86111450195312, 58.431427001953125], [-173.2819366455078, 66.99493408203125], [-167.4853973388672, 83.30218505859375], [-156.63345336914062, 73.79769897460938]], [[-156.63345336914062, 73.79769897460938], [-167.4853973388672, 83.30218505859375], [-160.36532592773438, 99.0565185546875], [-149.9940185546875, 88.627197265625]], [[-149.9940185546875, 88.627197265625], [-160.36532592773438, 99.0565185546875], [-151.93539428710938, 114.1326904296875], [-142.03211975097656, 102.82266235351562]], [[-142.03211975097656, 102.82266235351562], [-151.93539428710938, 114.1326904296875], [-142.20928955078125, 128.40542602539062], [-132.83712768554688, 116.28668212890625]], [[-132.83712768554688, 116.28668212890625], [-142.20928955078125, 128.40542602539062], [-132.1231292365946, 140.6314697265625], [-122.49836730957031, 128.922119140625]], [[-122.49836730957031, 128.922119140625], [-132.1231292365946, 140.6314697265625], [-131.20069885253906, 141.74960327148438], [-111.105224609375, 140.6314697265625]], [[-111.105224609375, 140.6314697265625], [-131.20069885253906, 141.74960327148438], [-118.92338555585833, 154.03985595703125], [-98.74700927734375, 151.31756591796875]], [[-98.74700927734375, 151.31756591796875], [-118.92338555585833, 154.03985595703125], [-94.98068835193737, 154.03985595703125]], [[-91.73934173583984, 40.044891357421875], [-106.64192962646484, 40.961181640625], [-102.25096893310547, 54.093902587890625], [-96.99297836955397, 65.71539306640625], [-86.42540740966797, 55.35137939453125]], [[168.77566528320312, 70.6102294921875], [184.49676813924987, 70.6102294921875], [187.06997680664062, 55.87957763671875], [187.40686376546213, 50.941314697265625], [172.71739196777344, 50.941314697265625]], [[162.4208526611328, 89.67071533203125], [179.2286979356434, 89.67071533203125], [179.57838439941406, 88.78121948242188], [184.1640167236328, 72.51510620117188], [184.49676813924987, 70.6102294921875], [168.77566528320312, 70.6102294921875]], [[153.80526733398438, 107.853271484375], [171.68410740348398, 107.853271484375], [173.389892578125, 104.52285766601562], [179.2286979356434, 89.67071533203125], [162.4208526611328, 89.67071533203125]], [[143.08128356933594, 124.88845825195312], [162.25931908699442, 124.88845825195312], [165.67538452148438, 119.5848388671875], [171.68410740348398, 107.853271484375], [153.80526733398438, 107.853271484375]], [[130.40121459960938, 140.50653076171875], [151.1831914210874, 140.50653076171875], [156.51161193847656, 133.81207275390625], [162.25931908699442, 124.88845825195312], [143.08128356933594, 124.88845825195312]], [[115.91741943359375, 154.43804931640625], [138.74601481290358, 154.43804931640625], [145.97537231445312, 147.04946899414062], [151.1831914210874, 140.50653076171875], [130.40121459960938, 140.50653076171875]], [[99.78219604492188, 166.4134521484375], [125.35045053135009, 166.4134521484375], [134.1435546875, 159.14187622070312], [138.74601481290358, 154.43804931640625], [115.91741943359375, 154.43804931640625]], [[82.14791107177734, 176.16314697265625], [111.62489563093311, 176.16314697265625], [121.09285736083984, 169.934326171875], [125.35045053135009, 166.4134521484375], [99.78219604492188, 166.4134521484375]], [[-86.42540740966797, 55.35137939453125], [-96.99297836955397, 65.71539306640625], [-96.53167724609375, 66.7349853515625], [-81.53887176513672, 65.71539306640625]], [[-81.53887176513672, 65.71539306640625], [-96.53167724609375, 66.7349853515625], [-89.55731201171875, 78.73660278320312], [-75.496337890625, 75.41888427734375]], [[-75.496337890625, 75.41888427734375], [-89.55731201171875, 78.73660278320312], [-81.40103149414062, 89.95111083984375], [-68.40731048583984, 84.3787841796875]], [[-68.40731048583984, 84.3787841796875], [-81.40103149414062, 89.95111083984375], [-72.58283126321481, 99.73504638671875], [-60.381317138671875, 92.51190185546875]], [[-60.381317138671875, 92.51190185546875], [-72.58283126321481, 99.73504638671875], [-72.13606262207031, 100.23074340820312], [-51.527870178222656, 99.73504638671875]], [[-51.527870178222656, 99.73504638671875], [-72.13606262207031, 100.23074340820312], [-61.835601806640625, 109.42779541015625], [-41.95648956298828, 105.9649658203125]], [[-41.95648956298828, 105.9649658203125], [-61.835601806640625, 109.42779541015625], [-53.79877924242567, 115.11270141601562], [-31.77667808532715, 111.11865234375]], [[-31.77667808532715, 111.11865234375], [-53.79877924242567, 115.11270141601562], [-50.57284164428711, 117.39459228515625], [-21.097965240478516, 115.11270141601562]], [[-21.097965240478516, 115.11270141601562], [-50.57284164428711, 117.39459228515625], [-47.07778462664281, 119.28964233398438], [-10.02985954284668, 117.8641357421875]], [[-10.02985954284668, 117.8641357421875], [-47.07778462664281, 119.28964233398438], [-46.64620021497564, 119.52365112304688], [1.3181166648864746, 119.28964233398438]], [[91.82200622558594, 73.73358154296875], [108.60551904095675, 73.73358154296875], [109.22047424316406, 72.5633544921875], [112.97816661930962, 62.95880126953125], [97.00892639160156, 62.95880126953125]], [[85.18205261230469, 83.52688598632812], [103.22577812063805, 83.52688598632812], [104.24851989746094, 82.02471923828125], [108.60551904095675, 73.73358154296875], [91.82200622558594, 73.73358154296875]], [[77.26873779296875, 92.2784423828125], [97.0349418195053, 92.2784423828125], [98.23646545410156, 90.85501098632812], [103.22577812063805, 83.52688598632812], [85.18205261230469, 83.52688598632812]], [[68.26178741455078, 99.92764282226562], [90.57822382349481, 99.92764282226562], [97.0349418195053, 92.2784423828125], [77.26873779296875, 92.2784423828125]], [[58.340919494628906, 106.41415405273438], [83.77242115344117, 106.41415405273438], [89.27932739257812, 101.4664306640625], [90.57822382349481, 99.92764282226562], [68.26178741455078, 99.92764282226562]], [[47.68586730957031, 111.67742919921875], [77.56930438159624, 111.67742919921875], [79.02140808105469, 110.6827392578125], [83.77242115344117, 106.41415405273438], [58.340919494628906, 106.41415405273438]], [[36.476341247558594, 115.65707397460938], [71.75959759728383, 115.65707397460938], [77.56930438159624, 111.67742919921875], [47.68586730957031, 111.67742919921875]], [[24.89206314086914, 118.29263305664062], [67.91206186393934, 118.29263305664062], [71.75959759728383, 115.65707397460938], [36.476341247558594, 115.65707397460938]], [[13.112751960754395, 119.52365112304688], [65.59938528136169, 119.52365112304688], [67.66618347167969, 118.4610595703125], [67.91206186393934, 118.29263305664062], [24.89206314086914, 118.29263305664062]], [[1.3181166648864746, 119.28964233398438], [-46.64620021497564, 119.52365112304688], [13.112751960754395, 119.52365112304688]], [[-38.42099380493164, 123.98342895507812], [-25.4532527923584, 129.04653930664062], [-12.114139556884766, 132.53396606445312], [1.5519838333129883, 134.28335571289062], [15.341647148132324, 134.33770751953125], [29.051372528076172, 132.73980712890625], [42.47768783569336, 129.532470703125], [55.4171142578125, 124.75860595703125], [65.59938528136169, 119.52365112304688], [-46.64620021497564, 119.52365112304688]], [[-100.21424102783203, 169.71759033203125], [-85.51312255859375, 160.88299560546875], [-94.98068835193737, 154.03985595703125], [-118.9233169555664, 154.03985595703125]], [[-85.51312255859375, 160.88299560546875], [-100.21424102783203, 169.71759033203125], [-87.63823188040341, 177.54388427734375], [-70.44490814208984, 169.98309326171875]], [[-70.44490814208984, 169.98309326171875], [-87.63823188040341, 177.54388427734375], [-79.60450744628906, 182.54342651367188], [-54.537025451660156, 177.54388427734375]], [[-54.537025451660156, 177.54388427734375], [-79.60450744628906, 182.54342651367188], [-67.84250018894451, 187.83267211914062], [-37.96284103393555, 183.51168823242188]], [[-37.96284103393555, 183.51168823242188], [-67.84250018894451, 187.83267211914062], [-62.01544823159079, 190.45303344726562], [-20.895767211914062, 187.83267211914062]], [[-20.895767211914062, 187.83267211914062], [-62.01544823159079, 190.45303344726562], [-60.08981467981226, 191.3189697265625], [-3.5091705322265625, 190.45303344726562]], [[-3.5091705322265625, 190.45303344726562], [-60.08981467981226, 191.3189697265625], [14.023551940917969, 191.3189697265625]], [[65.76456451416016, 182.85269165039062], [99.78013212237508, 182.85269165039062], [106.90019226074219, 179.27145385742188], [111.62489563093311, 176.16314697265625], [82.14791107177734, 176.16314697265625]], [[48.83381271362305, 187.57257080078125], [90.39627510439473, 187.57257080078125], [99.78013212237508, 182.85269165039062], [65.76456451416016, 182.85269165039062]], [[31.52900505065918, 190.37680053710938], [84.67952877840162, 190.37680053710938], [85.12433624267578, 190.2242431640625], [90.39627510439473, 187.57257080078125], [48.83381271362305, 187.57257080078125]], [[14.023551940917969, 191.3189697265625], [81.93247119797832, 191.3189697265625], [84.67952877840162, 190.37680053710938], [31.52900505065918, 190.37680053710938]], [[-57.48405075073242, 192.49075317382812], [-34.242889404296875, 199.53265380859375], [-10.270980834960938, 203.6424560546875], [14.041683197021484, 204.79327392578125], [38.30510711669922, 202.9583740234375], [62.129329681396484, 198.11093139648438], [81.93247119797832, 191.3189697265625], [-60.08981467981226, 191.3189697265625]]] \ No newline at end of file diff --git a/examples/17-concave-phys-objects/main.py b/examples/17-concave-phys-objects/main.py index fa2e5d81..721b5b57 100644 --- a/examples/17-concave-phys-objects/main.py +++ b/examples/17-concave-phys-objects/main.py @@ -39,8 +39,8 @@ def __init__(self, **kwargs): def init_game(self): self.setup_states() - self.set_state() self.draw_some_stuff() + self.set_state() def destroy_created_entity(self, ent_id, dt): self.gameworld.remove_entity(ent_id) @@ -56,8 +56,8 @@ def load_svg(self, fname, gameworld): data = mm.get_model_info_for_svg(fname) posvel = { - 'spiral': ((200, 200), (0, 0)), - 'ball': ((500, 30), (-200, 0)) + 'spiral': ((300, 300), (0, 0)), + 'ball': ((600, 130), (-800, 0)) } for info in data['model_info']: @@ -74,9 +74,9 @@ def load_svg(self, fname, gameworld): shape = { 'shape_type': 'poly', - 'elasticity': 0.6, + 'elasticity': 0.8, 'collision_type': 1, - 'friction': 1.0, + 'friction': 0.1, 'shape_info': { 'mass': 50, 'offset': (0, 0), @@ -100,7 +100,7 @@ def load_svg(self, fname, gameworld): 'angle': 0, 'angular_velocity': radians(0), 'ang_vel_limit': radians(0), - 'mass': 50, + 'mass': 0 if info.element_id == 'spiral' else 50, 'col_shapes': shapes } @@ -111,17 +111,21 @@ def load_svg(self, fname, gameworld): 'rotate': radians(0), } - ent = gameworld.init_entity(create_dict, ['position', 'rotate', 'poly_renderer', 'cymunk_physics']) + #need to pause it a bit + Clock.schedule_once(partial(self.init_entity, create_dict)) self.app.count += 1 + def init_entity(self, create_dict, dt): + self.gameworld.init_entity(create_dict, ['position', 'rotate', 'poly_renderer', 'cymunk_physics']) + def update(self, dt): self.gameworld.update(dt) def setup_states(self): self.gameworld.add_state(state_name='main', - systems_added=['poly_renderer'], + systems_added=['poly_renderer', 'cymunk_physics'], systems_removed=[], systems_paused=[], - systems_unpaused=['poly_renderer'], + systems_unpaused=['poly_renderer', 'cymunk_physics'], screenmanager_screen='main') def set_state(self): diff --git a/examples/17-concave-phys-objects/objects.svg b/examples/17-concave-phys-objects/objects.svg index ca25679b..6a26ba4d 100644 --- a/examples/17-concave-phys-objects/objects.svg +++ b/examples/17-concave-phys-objects/objects.svg @@ -30,9 +30,9 @@ inkscape:window-height="1065" id="namedview8" showgrid="false" - inkscape:zoom="1.3906434" - inkscape:cx="298.82756" - inkscape:cy="27.37035" + inkscape:zoom="11.125147" + inkscape:cx="46.587027" + inkscape:cy="-12.588547" inkscape:window-x="1916" inkscape:window-y="-3" inkscape:window-maximized="1" @@ -98,17 +98,12 @@ + inkscape:connector-curvature="0" />