Пример #1
0
 def create_stanchions(self):
     from pandac.PandaModules import GeomVertexReader, CollisionNode, CollisionTube
     self.stanchions = self.stage.findAllMatches('**/=Stanchion')
     for stanchion in self.stanchions:
         geomnode = stanchion.node()
         radius = float(stanchion.getTag('Stanchion'))
         geom = geomnode.getGeom(0)
         vdata = geom.getVertexData()
         for gp in range(geom.getNumPrimitives()):
             vreader = GeomVertexReader(vdata, 'vertex')
             prim = geom.getPrimitive(gp)
             prim = prim.decompose()
             for p in range(prim.getNumPrimitives()):
                 start = prim.getPrimitiveStart(p)
                 end = prim.getPrimitiveEnd(p)
                 vertices = []
                 for v in range(start, end):
                     vi = prim.getVertex(v)
                     vreader.setRow(vi)
                     vertex = vreader.getData3f()
                     vertices.append(vertex)
                 vertices.append(vertices[0])
                 for i in range(1, len(vertices)):
                     a, b = vertices[i - 1], vertices[i]
                     stanchion_np = stanchion.attachNewNode(
                         CollisionNode('stanchion'))
                     print 'creating cyl with radius %f from %s to %s' % (
                         radius, a, b)
                     stanchion_np.node().addSolid(
                         CollisionTube(a[0], a[1], a[2], b[0], b[1], b[2],
                                       radius))
                     stanchion_np.node().setFromCollideMask(OBSTACLE_MASK)
         geomnode.removeAllGeoms()
Пример #2
0
def processVertexData(vdata):
  vertex = GeomVertexReader(vdata, 'vertex')
  texcoord = GeomVertexReader(vdata, 'texcoord')
  while not vertex.isAtEnd():
    v = vertex.getData3f()
    t = texcoord.getData2f()
    print "v = %s, t = %s" % (repr(v), repr(t))
Пример #3
0
 def create_stanchions(self):
     from pandac.PandaModules import GeomVertexReader, CollisionNode, CollisionTube
     self.stanchions = self.stage.findAllMatches('**/=Stanchion')
     for stanchion in self.stanchions:
         geomnode = stanchion.node()
         radius = float(stanchion.getTag('Stanchion'))
         geom = geomnode.getGeom(0)
         vdata = geom.getVertexData()
         for gp in range(geom.getNumPrimitives()):
             vreader = GeomVertexReader(vdata, 'vertex')
             prim = geom.getPrimitive(gp)
             prim = prim.decompose()
             for p in range(prim.getNumPrimitives()):
                 start = prim.getPrimitiveStart(p)
                 end = prim.getPrimitiveEnd(p)
                 vertices = []
                 for v in range(start, end):
                     vi = prim.getVertex(v)
                     vreader.setRow(vi)
                     vertex = vreader.getData3f()
                     vertices.append(vertex)
                 vertices.append(vertices[0])
                 for i in range(1, len(vertices)):
                     a, b =  vertices[i-1], vertices[i]
                     stanchion_np = stanchion.attachNewNode(CollisionNode('stanchion'))
                     print 'creating cyl with radius %f from %s to %s' % (radius, a, b)
                     stanchion_np.node().addSolid(CollisionTube(a[0], a[1], a[2], b[0], b[1], b[2], radius))
                     stanchion_np.node().setFromCollideMask(OBSTACLE_MASK)
         geomnode.removeAllGeoms()
Пример #4
0
 def _set_z_on_shaft(self, z):
     for vdata in self.shaft_vdata:
         reader = GeomVertexReader(vdata, 'vertex')
         writer = GeomVertexWriter(vdata, 'vertex')
         while not reader.isAtEnd():
             v = reader.getData3f()
             if v[2] > 0:
                 writer.setData3f(v[0],v[1],z)
             else:
                 writer.setData3f(v) # I have to call the writer setData method in any case 
Пример #5
0
 def set_bar_height(self, height):
     """ Sets the height of the bar to the given value. The given height should be between 0 and 1. """
     reader = GeomVertexReader(self.bar_vdata, 'vertex')
     writer = GeomVertexWriter(self.bar_vdata, 'vertex')
     while not reader.isAtEnd():
         v = reader.getData3f()
         if v[2] > 0:
             writer.setData3f(v[0],v[1],height)
         else:
             writer.setData3f(v) # I have to call the writer setData method in any case 
Пример #6
0
 def set_bar_height(self, height):
     """ Sets the height of the bar to the given value. The given height should be between 0 and 1. """
     reader = GeomVertexReader(self.bar_vdata, 'vertex')
     writer = GeomVertexWriter(self.bar_vdata, 'vertex')
     while not reader.isAtEnd():
         v = reader.getData3f()
         if v[2] > 0:
             writer.setData3f(v[0], v[1], height)
         else:
             writer.setData3f(
                 v)  # I have to call the writer setData method in any case
Пример #7
0
 def _set_z_on_shaft(self, z):
     for vdata in self.shaft_vdata:
         reader = GeomVertexReader(vdata, 'vertex')
         writer = GeomVertexWriter(vdata, 'vertex')
         while not reader.isAtEnd():
             v = reader.getData3f()
             if v[2] > 0:
                 writer.setData3f(v[0], v[1], z)
             else:
                 writer.setData3f(
                     v
                 )  # I have to call the writer setData method in any case
Пример #8
0
def processPrimitive(prim, vdata):
  vertex = GeomVertexReader(vdata, 'vertex')
  prim = prim.decompose()
  for p in range(prim.getNumPrimitives()):
    s = prim.getPrimitiveStart(p)
    e = prim.getPrimitiveEnd(p)
    for i in range(s, e):
      vi = prim.getVertex(i)
      vertex.setRow(vi)
      v = vertex.getData3f()
      print "prim %s has vertex %s: %s" % (p, vi, repr(v))
    print
Пример #9
0
    def scale_vertices(self, multiplier):
        """
        Scale the working vertices as the given multiplier to the original
        vertices.

        @type multiplier: number
        @param multiplier: Coefficient to apply to original vertices.
        """

        for i,geom in self.__get_geoms():
            orig_vdata = self.orig_vertices[i]
            working_vdata = self.working_vertices[i]

            reader = GeomVertexReader(orig_vdata, 'vertex')
            writer = GeomVertexWriter(working_vdata, 'vertex')

            while not reader.isAtEnd():
                data = reader.getData3f()
                writer.setData3f(data[0] * multiplier,
                                 data[1] * multiplier,
                                 data[2] * multiplier)
Пример #10
0
 def _set_threshold(self, vdata, t_value):
     reader = GeomVertexReader(vdata, 'vertex')
     writer = GeomVertexWriter(vdata, 'vertex')
     while not reader.isAtEnd():
         v = reader.getData3f()
         writer.setData3f(v[0], v[1], t_value + self.padding)
Пример #11
0
    def from_triangles(cls, triangle_geom_node):
        _log = logging.getLogger("HalfEdgeMesh")
        tri_geom = triangle_geom_node.getGeom(0)  # assume that the triangle list is in the first geom in the node
        tri_primitive = tri_geom.getPrimitive(0)  # assume that the triangle list is the first primitive in the geom
        vdata = tri_geom.getVertexData()
        vertex_reader = GeomVertexReader(vdata, "vertex")
        normal_reader = GeomVertexReader(vdata, "normal")
        # halfedges          = zeros((tri_primitive.getNumPrimitives()*3,), dtype=cls.halfedge_dtype)
        # faces              = zeros((tri_primitive.getNumPrimitives()  ,), dtype=cls.face_dtype)
        # temp_vertices      = zeros((vdata.getNumRows(),), dtype=cls.vertex_dtype)
        halfedges = []
        faces = []
        vertices = []
        identity_threshold = 0.00001

        _log.debug(
            u"Creating mesh from %d vertices and %d faces..." % (vdata.getNumRows(), tri_primitive.getNumPrimitives())
        )

        vertex_count = 0
        vertex_index = 0
        edge_index = 0
        face_index = 0
        for triangle_index in range(tri_primitive.getNumPrimitives()):
            # add vertices
            vertex_start = tri_primitive.getPrimitiveStart(triangle_index)
            vertex_end = tri_primitive.getPrimitiveEnd(triangle_index)
            edge_base = edge_index
            for prim_vertex_index in range(vertex_start, vertex_end):
                vertex_reader.setRow(prim_vertex_index)
                coordinates = array(vertex_reader.getData3f())

                # find duplicate within a threshold
                # same_vertices = [ vertex_index for vertex_index, vertex_data in enumerate(temp_vertices[:vertex_count]) if not any(fabs(vertex_data['coord'] - vertex) > identity_threshold) ]
                vertex = None
                for vertex_data in vertices:
                    if not any(fabs(vertex_data.coordinates - coordinates) > identity_threshold):
                        vertex = vertex_data
                        break
                if vertex is None:
                    # new vertex
                    normal_reader.setRow(prim_vertex_index)
                    normal = array(normal_reader.getData3f())
                    vertex = Vertex(coordinates, normal, edge_index)
                    vertices.append(vertex)
                    vertex_count += 1

                # add edge
                halfedges.append(Halfedge(vertex, edge_base + (edge_index - edge_base + 1) % 3, None, None))
                edge_index += 1

            # add face
            face = Face(halfedges[edge_base])
            faces.append(face)
            face_index += 1
            # determine matching face
            for edge_data in halfedges[edge_base:]:
                edge_data.face = face

        _log.debug(u"Found %d unique vertices with %d halfedges and %d faces." % (vertex_count, edge_index, face_index))

        for vertex_data in vertices:
            vertex_data.edge = halfedges[vertex_data.edge]

        # resolve 'next' edges
        for edge_data in halfedges:
            edge_data.next = halfedges[edge_data.next]

        # determine 'opposite' edges
        for edge_data in halfedges:
            if edge_data.opposite == None:
                v1 = edge_data.origin
                v2 = edge_data.next.origin
                for opposite_edge_data in halfedges:
                    if opposite_edge_data.origin == v2 and opposite_edge_data.next.origin == v1:
                        edge_data.opposite = opposite_edge_data
                        opposite_edge_data.opposite = edge_data
                        break

        _log.debug(u"Done creating mesh.")
        return cls(vertices, halfedges, faces)
Пример #12
0
 def _set_threshold(self, vdata, t_value):
     reader = GeomVertexReader(vdata, 'vertex')
     writer = GeomVertexWriter(vdata, 'vertex')
     while not reader.isAtEnd():
         v = reader.getData3f()
         writer.setData3f(v[0],v[1],t_value+self.padding)