本文整理汇总了Python中Polygon.Polygon.triStrip方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.triStrip方法的具体用法?Python Polygon.triStrip怎么用?Python Polygon.triStrip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon.Polygon
的用法示例。
在下文中一共展示了Polygon.triStrip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import triStrip [as 别名]
def main(filein, fileout, width, height, gap):
d = dxfgrabber.read(filein)
def flipxy(p):
return (p[1], p[0])
layers = {}
for r in d.entities:
if not r.layer in layers:
layers[r.layer] = []
layers[r.layer].append(map(flipxy, r.points))
polys_to_cut = []
for (_, ps) in layers.iteritems():
polys_to_cut += map(lambda p: geo.extend_poly(gap, p, False), ps)
h = height / 2.0
w = width / 2.0
gndplane = Polygon([(h, w), (-h, w), (-h, -w), (h, -w)])
for p in polys_to_cut:
gndplane = gndplane - Polygon(p)
# Polygon.triStrip() returns a list of tristrips which need to be
# turned into quads, and the list needs to be flattened.
layers["GROUND"] = [
quad for quads in map(
geo.tristrip_to_quads,
gndplane.triStrip())
for quad in quads]
drawing = DXFEngine.drawing(fileout)
for (l, qs) in layers.iteritems():
for q in qs:
drawing.add(DXFEngine.face3d(map(flipxy, q), layer=l))
drawing.save()
示例2: set_shape
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import triStrip [as 别名]
def set_shape(self, shape):
if not import_check("Polygon"):
return
# shape can be a Polygon object or a simple list of points
# Construct a pointer array with this integer format:
# (number of contours,closed), where closed=1 for shape=Polygon object
# but closed=0 for shape=list of points with final != initial.
# In both Polygon and list cases if final == initial, final is discarded
# (length of 1st contour, offset in array to data for 1st contour)
# (length of 2nd contour, offset in array to data for 2nd contour)
# .....
# Construct a contour array with this float format:
# (x,y) data for 1st contour
# (x,y) data for 2nd contour
# .....
datalist = []
if isinstance(shape, str):
shape = shapes.text(text=shape, align='center')
else:
try:
shape.pos # could be a paths.xxx object, a list of vectors
s = []
for v in shape.pos:
s.append((v.x, -v.z))
shape = Polygon(s)
except:
pass
try:
for i in range(len(shape)):
s = list(shape.contour(i))
if s[-1] == s[0]: # discard final point if same as initial
s = s[:-1]
c = self.xycurl(s) # positive if CCW
# Require hole contours to run CCW, external contours CW
if (shape.isHole(i) and (c < 0) or
(not shape.isHole(i)) and (c > 0)):
# Need to reverse the order of points in this contour
s.reverse()
datalist.append(s)
closed = True
isPolygon = True
except:
s = shape
# Require (external) closed contour to run clockwise (curl > 0)
if self.xycurl(s) > 0: # Need to reverse the order of points in this contour
s.reverse()
if s[-1] == s[0]: # discard final point if same as initial, mark closed
s = s[:-1]
closed = True
else:
closed = False
isPolygon = False
datalist = array([s], float)
contours, pcontours = self.make_shapedata(datalist, closed)
if isPolygon:
strips, pstrips = self.make_shapedata(shape.triStrip(), closed)
else:
strips = array([(0,0)])
pstrips = array([(0,0)])
# Send pointers, contour data, and shape.triStrip data to Visual
self.set_contours(contours, pcontours, strips, pstrips)
示例3: Chunk
# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import triStrip [as 别名]
class Chunk(object):
underground_texture = None
def __init__(self, world, chunk_pos):
self.world = world
self.pos = (chunk_pos[0] * 51.2, chunk_pos[1] * 51.2)
self.chunk_pos = (chunk_pos[0] % 32, chunk_pos[1])
self.texture = None
self.polygon = None
self.body = None
self.entities = []
self.things_to_blit = []
texture_filename = "data/world/%i_%i.tga" % self.chunk_pos
if os.path.exists(texture_filename):
self.texture = pygame.image.load(texture_filename)
self.texture.set_colorkey((255, 0, 255))
elif chunk_pos[1] <= 1:
self.texture = Chunk.underground_texture
data_filename = "data/world/%i_%i.dat" % self.chunk_pos
if os.path.exists(data_filename):
with open(data_filename) as fin:
self.polygon, self.entities = pickle.load(fin)
elif chunk_pos[1] <= 1:
self.polygon = Polygon((
(-25.6, -25.6),
(-25.6, 25.6),
(25.6, 25.6),
(25.6, -25.6)
))
self.load_body()
def load_body(self):
if self.body:
self.world.b2world.DestroyBody(self.body)
self.body = None
if not self.polygon:
return
shapes = []
for strip in self.polygon.triStrip():
for i in range(len(strip) - 2):
try:
shapes.append(b2PolygonShape(vertices=strip[i:i+3]))
except:
pass
self.body = self.world.b2world.CreateStaticBody(
position=(self.pos[0] + 25.6, self.pos[1] - 25.6),
shapes=shapes
)
def update(self, delta, player_pos):
for entity in self.entities:
entity.update(delta, self.pos, player_pos)
def render(self, screen, camera):
pos = camera.screen_pos(self.pos)
if self.texture:
screen.blit(self.texture, pos)
#if self.body:
# draw_body(self.body, screen, camera)
def unload(self):
if self.body:
self.world.b2world.DestroyBody(self.body)
for texture, pos in self.things_to_blit:
if self.texture == Chunk.underground_texture:
self.texture = Chunk.underground_texture.copy()
self.texture.set_colorkey((255, 0, 255))
pos = (
(pos[0] - self.pos[0]) * 10.0 - texture.get_width() / 2,
(self.pos[1] - pos[1]) * 10.0 - texture.get_height() / 2
)
self.texture.blit(texture, pos)
if self.texture:
pygame.image.save(
self.texture, "data/world/%i_%i.tga" % self.chunk_pos
)
with open("data/world/%i_%i.dat" % self.chunk_pos, "w") as fout:
pickle.dump((self.polygon, self.entities), fout)
def carve(self, body):
if not self.polygon:
return
if self.texture == Chunk.underground_texture:
self.texture = Chunk.underground_texture.copy()
self.texture.set_colorkey((255, 0, 255))
for fixture in body.fixtures:
shape = fixture.shape
vertices = [tuple(body.transform * x) for x in shape.vertices]
vertices = [
(x - self.pos[0] - 25.6, y - self.pos[1] + 25.6)
for (x, y) in vertices
]
polygon = Polygon(vertices)
self.polygon -= polygon
if self.texture:
#.........这里部分代码省略.........