【问题标题】:Generate socket junctions for 3D model / Draw cylinders along edges为 3D 模型生成插座连接/沿边缘绘制圆柱体
【发布时间】:2014-11-12 00:57:00
【问题描述】:

我有这个处理草图,我试图在其中加载模型(.stl 或 .obj)并为每个边缘交叉点构建参数化套接字连接点。这些将是 3D 打印的,并且适当规格的杆将插入它们的孔中。

我已经能够在顶点处绘制球体(在模型上以 红色 表示),但我无法生成 绿色 插槽甚至杆粉红色

我可以得到模型边缘的坐标:

id: 0 0 {-25.805634,-23.170607,13.6315975} -> 1 {-16.868328,-10.148323,6.785455} f: 2
id: 1 1 {-16.868328,-10.148323,6.785455} -> 2 {-52.833824,-10.148322,16.799314} f: 2
....

有了这些我可以画一个Line3D(Vec3D a, Vec3D b) (toxi.geom.Line3D)

但我不想要 Line3D,我需要在它们之间画一个圆柱体,从而得到杆。如果您愿意的话,可以将线条拉伸或膨胀为 3D 体积...

WETriangleMesh whale, redmesh;

[bla bla bla]
然后在void setup()里面:

for(WingedEdge e : whale.edges.values()) {
    edges.add(e);
    drawSocket(e);
}

void drawSocket(WingedEdge e) {
    // draw size 2 balls at model vertices
    Sphere ball = new Sphere(e.a, 2);
    // convert to mesh at resolution 6 and add to redmesh
    ball.toMesh(redmesh, 6);
}

然后在void draw()

// draw the mesh with the whale
gfx.mesh(whale);
// color the next mesh red
fill(255,0,0);
// draw the mesh with the spheres
gfx.mesh(redmesh);

我发现没有可以从Vec3D a, Vec3D b 参数就地构建的 3D 形状类。也许创建一个类来使用这两个坐标?

如果就地构建形状太难了,那么也许是变换? pushMatrix()translate()popMatrix()?

编辑:已解决,见下文。谢谢!

【问题讨论】:

    标签: vector 3d processing 3d-modelling


    【解决方案1】:

    诀窍是将套接字转换到边缘的一个顶点,并让它们面对相反的顶点。这是一个处理函数,它将像您的鲸鱼一样采用 WETriangleMesh,并返回用于点、插座和杆的网格。我写了一个更完整的例子here

    float socketLength = 30;
    float socketRadius = 6;
    float rodRadius = 5;
    float pointRadius = 10.0;
    int resolution = 10;
    
    WETriangleMesh[] convertMeshToRodSockets(WETriangleMesh inMesh) {
      WETriangleMesh[] meshes = new WETriangleMesh[3];
    
      meshes[0] = new WETriangleMesh();
      meshes[1] = new WETriangleMesh();
      meshes[2] = new WETriangleMesh();
    
      for (Vertex vert : inMesh.getVertices ()) {
        //Sphere points
        Sphere sphere = new Sphere(vert, pointRadius);
        WETriangleMesh sphereMesh = new WETriangleMesh();
        sphere.toMesh(sphereMesh, resolution);
        meshes[2].addMesh((WETriangleMesh)sphereMesh);
      }
    
      for (WingedEdge edge : inMesh.edges.values ()) {
        Vec3D pointA = edge.a;
        Vec3D pointB = edge.b;
    
        //Meshes to store socket shapes
        ZAxisCylinder socket;
        ZAxisCylinder rod;
        WETriangleMesh socketAMesh = new WETriangleMesh();
        WETriangleMesh socketBMesh = new WETriangleMesh();
        WETriangleMesh rodMesh = new WETriangleMesh();
    
        float distanceBetweenPoints = pointA.distanceTo(pointB);
    
        //Create sockets and point towards target
        socket = new ZAxisCylinder(new Vec3D(0.0, 0.0, 0.0), socketRadius, socketLength);
        socket.toMesh(socketAMesh, resolution, 0.0);
        socketAMesh.pointTowards(pointB.sub(pointA));
    
        //Translate socket to start from the center of the point
        socketAMesh.translate( offsetTranslation(pointA, pointB, socketLength ));
    
        //Create second socket and look in the opposite direction to face the start point
        socket.toMesh(socketBMesh, resolution, 0.0);
        socketBMesh.pointTowards(pointA.sub(pointB));
        socketBMesh.translate( offsetTranslation(pointB, pointA, socketLength ));
    
        //Create rod with a length matching the distance between the two points
        rod = new ZAxisCylinder(new Vec3D(0.0, 0.0, 0.0), rodRadius, distanceBetweenPoints);
        rod.toMesh(rodMesh, resolution, 0.0);
        rodMesh.pointTowards(pointB.sub(pointA));
    
        //Translate the rod to the midpoint of both points
        rodMesh.translate(pointA.add(pointB).scale(0.5));
    
        //Combine meshes together
        meshes[0].addMesh((WETriangleMesh)rodMesh);
        meshes[1].addMesh((WETriangleMesh)socketAMesh);
        meshes[1].addMesh((WETriangleMesh)socketBMesh);
      }
    
      return meshes;
    }
    
    //Function to return a vector that is slightly offset by a length.
    Vec3D offsetTranslation(Vec3D a, Vec3D b, float l) {
      return a.interpolateTo(b, (l*0.5 / a.distanceTo(b)) );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2014-02-23
      • 2017-08-22
      • 1970-01-01
      • 2011-02-10
      相关资源
      最近更新 更多