Help reagarding creating flat Disc-shape Geometry

Hello everyone.
I want to construct a disk shape within a particular thickness and radius. How can I do so in panda3d? there are no disk models available, so i wrote some sample code…Since i am new to panda3d, little unsure. The disk does not render on the scene…
task:
Disk should be at the render_origin(also given as tablepos)
thickness 0.2
radius 0.8

the entire scene is already scale but the disk does not appear
code

from panda3d.core import NodePath, GeomNode, GeomVertexData, Geom, GeomTristrips, GeomVertexWriter
from panda3d.core import GeomVertexFormat, GeomVertexArrayFormat, GeomVertexReader
from panda3d.core import GeomTriangles, GeomVertexRewriter
from panda3d.core import LVecBase3f, LPoint3f
from direct.showbase.ShowBase import ShowBase
from os.path import join
import argparse
import math

class GlassTableScene(ShowBase):
def init(self, base_path):
ShowBase.init(self)

    self.scene = self.loader.loadModel(join(base_path, 'P44_calib.bam'))
    self.scene.reparentTo(self.render)
    table_pos = self.scene.getPos()   # 0,0,0
    self.draw_disk_on_scene(table_pos)
    
def draw_disk_on_scene(self, table_pos):
    radius =  0.8
    thickness = 0.2
    
    disk = self.create_disk(radius, thickness)
    print(disk.getPos())  # also 0,0,0
    disk.setScale(self.render, 100)
    disk.setPos(table_pos)
    
    disk.reparentTo(self.render)
    
def create_disk(self, radius, thickness):
    geom_node = GeomNode("Disk")
    vertex_data = GeomVertexData("disk_data", GeomVertexFormat.getV3(), Geom.UHStatic)
    vertex_writer = GeomVertexWriter(vertex_data, 'vertex')
    
    # For a simple disk, generate vertices in a circular pattern
    # You can generate vertices using polar coordinates
    num_segments = 36  # Increase for a smoother circle

    for i in range(num_segments):
        angle = (2 * math.pi / num_segments) * i
        x = radius * math.cos(angle)
        y = radius * math.sin(angle)
        z = 0  # Flat on the table surface (z = 0 since the disk is on the table)
        vertex_writer.addData3(x, y, z)

    # Optionally, you can create another set of vertices for the edge thickness
    # Add more complex geometry if you want to show thickness.
    
    # Attach this geometry to the node and return
    geom = Geom(vertex_data)
    geom_node.addGeom(geom)

    # Wrap into a NodePath
    disk_node = NodePath(geom_node)
    return disk_node

much thanks in advance.

Greetings, and welcome to the forum! I hope that you find your time here to be positive! :slight_smile:

As to your question: It looks like you’re adding vertex-data to your Geom, but never creating any primitives–polygons, in this case–from that vertex-data. Naturally, you’re also not then adding those primitives to your geom.

I find that once I add those things to your code, I can in fact see the flat disc appear. :slight_smile: (After I move the camera back and rotate it down a bit, at least.)

See this manual page and the next for more information on specifying primitives and adding them to your Geom:
https://docs.panda3d.org/1.10/python/programming/internal-structures/procedural-generation/creating-primitives

1 Like

it worked. Thanks a lot for suggestion

1 Like