[Python] How to manipulate eyeglass frame parts (bridge, temples, lenses) as unified geometric...

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing an iOS app that communicates with a Blender server to allow real-time manipulation of 3D eyeglass frames. Currently, I can only manipulate individual vertices, but I need to manipulate entire frame parts (bridge, temples, lenses, nose pads) as cohesive geometric units.

    Current Problem:

    • My current approach modifies individual vertices based on position ranges
    • This results in unnatural deformations and doesn't maintain the structural integrity of frame parts
    • Users expect frame parts to scale/move/deform as unified objects

    What I Want to Achieve:

    • Bridge manipulation: Adjust width, height, and curvature while maintaining bridge geometry
    • Lens manipulation: Resize and reshape lens openings while preserving circular/oval forms
    • Temple manipulation: Adjust length and thickness while maintaining temple curve and taper
    • Nose pad manipulation: Move and resize nose pads as complete units

    Current Approach (Not Working Well):

    `# This manipulates individual vertices - not ideal
    def adjust_bridge_width(self, scale_factor):
    bridge_vertices = self.get_vertices_in_range(1965, 2000)
    for vert_idx in bridge_vertices:
    vert = self.frame_object.data.vertices[vert_idx]
    vert.co.x *= scale_factor # This distorts the geometry`


    What's the best approach for manipulating frame parts as unified geometric units in Blender?

    Should I use:

    • Vertex Groups with proportional editing?
    • Separate mesh objects for each frame part with constraints?
    • Armature/bone system to drive deformations?
    • Shape keys for predefined deformations?
    • Custom modifiers or geometry nodes?

    How can I maintain geometric integrity when scaling frame parts (e.g., keep bridge curves smooth, maintain lens circularity)?

    What's the recommended way to implement real-time frame adjustments that could be controlled via REST API calls?

    Technical Context:

    • Using Blender 3.x with Python API
    • Frame models are imported STL files
    • Need to support real-time adjustments via HTTP requests
    • Target output is updated STL files for 3D printing

    Specific Use Cases:

    `# What I want to achieve:
    manipulator.adjust_bridge_width(1.2) # 20% wider bridge
    manipulator.adjust_lens_size(0.9) # 10% smaller lenses
    manipulator.adjust_temple_length(1.1) # 10% longer temples
    manipulator.adjust_nose_pad_spacing(1.15) # 15% wider nose pad spacing`


    Any guidance on the proper Blender techniques for this type of parametric frame manipulation would be greatly appreciated! Additional Info:

    • Current frame has ~3000 vertices
    • Need to maintain printable geometry (no self-intersections)
    • Performance is important for real-time adjustments

    I tried several approaches to manipulate eyeglass frame parts as unified geometric units, but they all resulted in unnatural vertex-level distortions instead of proper frame part transformations.

    Approach 1: Position-based vertex grouping with scaling

    `def adjust_bridge_width(self, scale_factor):
    # Find bridge vertices by position
    bridge_vertices = []
    for i, vert in enumerate(self.frame.data.vertices):
    if -0.5 <= vert.co.x <= 0.5 and vert.co.z > 0.3:
    bridge_vertices.append(i)

    # Scale from calculated center
    center_x = sum(self.frame.data.vertices.co.x for i in bridge_vertices) / len(bridge_vertices)
    for i in bridge_vertices:
    vert = self.frame.data.vertices
    vert.co.x = (vert.co.x - center_x) * scale_factor + center_x`


    Expected: Bridge should scale uniformly while maintaining its natural curve and structural integrity.

    Result: Individual vertices moved independently, creating jagged distortions and breaking the smooth bridge geometry.

    Approach 2: Unified transformation with offset calculations

    `def adjustFramePartVertices(self, part, adjustment_type, scale_factor):
    # Find all vertices belonging to frame part
    part_vertices = self.detect_part_vertices(part)
    center = self.calculate_center(part_vertices)

    # Apply unified transformation
    for vertex_index in part_vertices:
    current_pos = self.get_vertex_position(vertex_index)
    new_position = self.calculate_new_position(current_pos, center, part, scale_factor)
    offset = new_position - current_pos
    self.adjust_vertex(vertex_index, offset)`


    Expected: Frame parts would transform as cohesive units (bridge widens smoothly, lenses resize proportionally, temples extend naturally).

    Result: Still getting vertex-level manipulation where individual points move independently. The bridge becomes uneven, lens shapes become polygonal instead of smooth, and temples develop kinks.

    Approach 3: Vertex ranges with proportional editing

    `# Using predefined vertex ranges for frame parts
    bridge_range = range(1965, 2001) # 36 vertices
    left_lens_range = range(0, 501) # 501 vertices
    right_lens_range = range(501, 1000) # 499 vertices

    for i in bridge_range:
    vertex = self.frame.data.vertices
    # Apply transformation relative to part center
    vertex.co *= scale_matrix`


    Expected: Using vertex ranges would ensure all bridge vertices move together as a unit.

    Result: Vertices move in unnatural ways that don't respect the original geometry's curvature and flow. The bridge loses its smooth transition to the lens areas.

    Core Problem: All approaches treat vertices as independent points rather than part of a continuous surface that should deform naturally. I need the bridge to maintain its curvature when scaled, lenses to preserve their circular/oval shape when resized, and temples to extend smoothly when lengthened.

    What I'm missing: A proper methodology for maintaining geometric relationships and surface continuity during transformations. The frame parts should behave like they're made of a flexible material that maintains its shape characteristics while being adjusted.

    Continue reading...

Compartilhe esta Página