def primitives(self, vdata):
     vertex = GeomVertexWriter(vdata, 'vertex')
     color = GeomVertexWriter(vdata, 'color')
     n = len(self.border)
     # Points
     for p in self.border:
         vertex.addData3f(p.x, p.y, p.z)
         color.addData4f(0.5, 0.5, 0.5, 0.0)
     for p in self.border:
         vertex.addData3f(p.x, p.y, p.z + self.top)
         color.addData4f(1.0, 1.0, 1.0, 0.0)
     # Wall
     wall = GeomTristrips(Geom.UHStatic)
     for i in range(n):
         wall.addVertices(i, i + n)
     wall.addVertices(0, n)
     wall.closePrimitive()
     yield wall
     # Ceiling
     if self.cover:
         ceil = GeomTristrips(Geom.UHStatic)
         ceil.addConsecutiveVertices(n, n)
         ceil.addVertex(n)
         ceil.closePrimitive()
         yield ceil
Beispiel #2
0
 def primitives(self, vdata):
     vertex = GeomVertexWriter(vdata, 'vertex')
     color = GeomVertexWriter(vdata, 'color')
     r = int(self.diameter / 2.0)
     n = 0
     for i in range(-r, r + 1, self.resolution):
         for j in range(-r, r + 1, self.resolution):
             h = elevation(i, j)
             vertex.addData3f(i, j, h)
             color.addData4f(elevation_color(h))
         n += 1
     for i in range(n - 1):
         row = GeomTristrips(Geom.UHStatic)
         for j in range(n):
             t = i * n + j
             b = t + n
             row.addVertices(t, b)
         row.closePrimitive()
         yield row
Beispiel #3
0
    def _get_primitive(cls, layer: Layer) -> GeomTristrips:
        """Generate GeomTristrips primitive for provided layer."""
        primitive = GeomTristrips(Geom.UHStatic)

        cur_point_num_in_layer = 0

        # Iterate over paths in layer
        for path in layer.paths:
            segment_count = len(path) - 1
            path_start_point_index = (
                cur_point_num_in_layer * 4
            )  # Relative to first point in first path in layer

            # Start cap
            primitive.addVertices(
                *[path_start_point_index + i for i in [0, 1, 3, 2]])
            primitive.closePrimitive()

            # Segment walls
            for segment_index in range(segment_count):
                v_start_index = path_start_point_index + segment_index * 4

                # Zigzag around segment walls: 0, 4, 1, 5, 2, 6, 3, 7, 0, 4
                for i in range(v_start_index, v_start_index + 4):
                    primitive.addVertex(i)
                    primitive.addVertex(i + 4)

                primitive.addVertex(v_start_index)
                primitive.addVertex(v_start_index + 4)

                primitive.closePrimitive()

            # End cap
            end_wall_start_index = (cur_point_num_in_layer + segment_count) * 4
            primitive.addVertices(
                *[end_wall_start_index + i for i in [0, 3, 1, 2]])
            primitive.closePrimitive()

            cur_point_num_in_layer += len(path)

        return primitive
Beispiel #4
0
 def primitives(self, vdata):
     vertex = GeomVertexWriter(vdata, 'vertex')
     color = GeomVertexWriter(vdata, 'color')
     w = ROAD_WIDTH / 2.0
     v = 0
     for a, b in self.edges:
         a, b = self.points[a], self.points[b]
         ab = b - a
         n = ab.length()
         inc = abs(a.z - b.z) / n
         probes = max(2, n / 25)
         ab_ = Vec3(ab)
         ab_.normalize()
         pab = Vec3.up().cross(ab_) * w
         road = GeomTristrips(Geom.UHStatic)
         for i in range(0, int(probes) + 1):
             p = a + ab / probes * i
             p1 = p + pab
             p2 = p - pab
             z = max(elevation(p1.x, p1.y), elevation(p2.x, p2.y))
             p1.z = z + 0.2
             p2.z = z + 0.2
             vertex.addData3f(p1)
             vertex.addData3f(p2)
             if inc > 0.1:
                 color.addData4f(0.4, 0.0, 0.0, 0.0)
                 color.addData4f(0.4, 0.0, 0.0, 0.0)
             elif n > 1000:
                 color.addData4f(0.0, 0.0, 0.4, 0.0)
                 color.addData4f(0.0, 0.0, 0.4, 0.0)
             else:
                 color.addData4f(0.2, 0.2, 0.2, 0.0)
                 color.addData4f(0.2, 0.2, 0.2, 0.0)
             road.addVertices(v, v + 1)
             v += 2
         road.closePrimitive()
         yield road
Beispiel #5
0
    def _get_node_plate(cls,
                        loader: Loader,
                        build_plate_size: LVector2d,
                        name: str = "") -> NodePath:
        """Generate the textured build plate NodePath.

        This NodePath's only purpose is to display the app's logo.

        Parameters
        ----------
        loader : Loader
            Panda3D asset loader.
        build_plate_size : LVector2d
            Builder plate size.
        name : str
            Name for the generated NodePath.
        """
        # Geom data
        geom_data = cls._get_geom_data_plate(build_plate_size)

        # Primitive
        primitive = GeomTristrips(Geom.UHStatic)
        primitive.addVertices(0, 1, 3, 2)
        primitive.closePrimitive()

        # Geom, GeomNode
        geom = Geom(geom_data)
        geom.addPrimitive(primitive)
        geom_node = GeomNode("")
        geom_node.addGeom(geom)

        # NodePath
        node_path = NodePath(top_node_name=name)
        node_path.attachNewNode(geom_node)

        # Texture
        tex = loader.loadTexture(cls._PATH_TEXTURE)
        ts = TextureStage("ts")
        node_path.setTexture(ts, tex)
        tex.setBorderColor((0, 0, 0, 0))
        tex.setWrapU(Texture.WMBorderColor)
        tex.setWrapV(Texture.WMBorderColor)

        node_path.setTransparency(TransparencyAttrib.MAlpha)
        node_path.setAlphaScale(cls._TEXTURE_OPACITY)

        texture_scale = cls._TEXTURE_SCALE

        width, height = build_plate_size
        ratio = width / height
        if ratio >= 1:  # Landscape or square
            scale_v = 1 / texture_scale
            scale_u = scale_v * ratio
        else:  # Portrait
            scale_u = 1 / texture_scale
            scale_v = scale_u / ratio

        node_path.setTexScale(ts, scale_u, scale_v)
        node_path.setTexOffset(ts, -0.5 * (scale_u - 1), -0.5 * (scale_v - 1))

        return node_path