如何通过添加路径动态构造3D对象? (Java;OpenGL)

发布于 2024-08-22 04:12:45 字数 920 浏览 7 评论 0原文

所以我有一些路径生成器,现在的工作方式如下

http://www.openprocessing.org/ Visuals/?visualID=2615 (有源代码;WQRNING - JAVA Applet)

我想使用我生成的路径创建一些 3D 对象,因此它锁定在类似于我现在在 2D 中获得的视角之一。

那么如何通过添加路径来动态构造 3D 对象呢?

顺便说一句:实际上我像这样的算法 http://www.derschmale.com/2009/07/20/slice-based-volume-rendering-using-pixel-bender/

所以我想从这样的路径创建(我不想使用图像,我不想使用 flash 我想使用 Java + OpenGl)

alt text

这样的 3D 图像(但请注意我想要 openGL Java 和路径))

替代文字

So I have some path generator which now works like this

http://www.openprocessing.org/visuals/?visualID=2615 (There is source; WQRNING - JAVA APPLET)

I want to create some 3D object using paths I generated so it locked in one of perspectives similar to what I get now in 2D.

So how do I dynamically construct 3D object by adding paths?

BTW: actually I ment algorithm like this http://www.derschmale.com/2009/07/20/slice-based-volume-rendering-using-pixel-bender/

So I want to create from such PATH (I do not want to use images and I do not want to use flash I want to use Java + OpenGl)

alt text

such 3d image (But note I want openGL Java and Path's))

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清晨说晚安 2024-08-29 04:12:45

我不确定我明白你在追求什么。

您提供的示例绘制了 2d 路径,但仅使用 z。缩放会起作用
以类似的方式。

那么如何动态地构建 3d
通过添加路径的 ? 来对象

您的意思是挤压/车削一个物体,还是复制挤压草图?

绘制路径很容易处理,您只需将顶点对象放置在for循环
beginShape()endShape() 调用之间。

这是在您发送的示例中执行此操作的代码:

 beginShape(); 
  for (int p=0; p<pcount; p++){ 
    vertex(Ring[p].position().x(),Ring[p].position().y()); 
  } 
  endShape(CLOSE);

您还可以调用 vertex(x,y,z)

我想在不久前挤出一条路径,这是我的 问题以防有帮助。

基本草图上传于此处

编辑:
如果你有一个由 2 个多边形组成的数组,你可以循环遍历它们,然后绘制
使用类似于 beginShape() 和 endShape() 的东西,GL_POLYGON 可能会很方便。

例如,

import processing.opengl.*;
import javax.media.opengl.*;

int zSpacing = 10;
PVector[][] slices;

void setup() {
  size(600, 500, OPENGL);

  slices = new PVector[3][3];
  //dummy slice 1
  slices[0][0] = new PVector(400, 200,-200);
  slices[0][1] = new PVector(300, 400,-200);
  slices[0][2] = new PVector(500, 400,-200);
  //dummy slice 2
  slices[1][0] = new PVector(410, 210,-200);
  slices[1][1] = new PVector(310, 410,-200);
  slices[1][2] = new PVector(510, 410,-200);
  //dummy slice 3
  slices[2][0] = new PVector(420, 220,-200);
  slices[2][1] = new PVector(320, 420,-200);
  slices[2][2] = new PVector(520, 420,-200);
}

void draw() {
  background(255);

  PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  // g may change
  GL gl = pgl.beginGL();  // always use the GL object returned by beginGL

  for(int i = 0 ; i < slices.length; i ++){
    gl.glColor3f(0, .15 * i, 0);
    gl.glBegin(GL.GL_POLYGON);
    for(int j = 0; j < slices[i].length; j++){
      gl.glVertex3f(slices[i][j].x, slices[i][j].y,slices[i][j].z + (zSpacing * i));
    }
    gl.glEnd();
  }
  pgl.endGL();
}

想法是循环遍历每个切片,并为每个切片循环遍历其所有点。显然,切片和每个切片内的 3d 向量数量取决于您的数据。说到这里,你的数据从哪里来?

如果切片不是您之后的 volTron 可能会派上用场:
volTron http://dm.ncl.ac.uk/joescully/voltronlib /images/s2.jpg

HTH,
乔治

I'm not sure I understand what you're after.

The example you supplied draws 2d paths, but merely uses z. scaling would have worked
in a similar way.

So How to dinamicly construct 3d
object by adding path's ?

Do you mean extruding/lathing an object, or replicating the scrunch sketch ?

Drawing a path is easy in processing, you just place vertex objects, in a for loop
between beginShape() and endShape() calls.

Here is the bit of code that does that in the example you've sent:

 beginShape(); 
  for (int p=0; p<pcount; p++){ 
    vertex(Ring[p].position().x(),Ring[p].position().y()); 
  } 
  endShape(CLOSE);

you can also call vertex(x,y,z)

I wanted to extrude a path a while back, here is my question in case it helps.

Basic sketch is uploaded here.

EDIT:
If you have an array of 2 polygons, you can just loop through them, and draw
using something similar to beginShape() and endShape(), GL_POLYGON might be handy.

e.g.

import processing.opengl.*;
import javax.media.opengl.*;

int zSpacing = 10;
PVector[][] slices;

void setup() {
  size(600, 500, OPENGL);

  slices = new PVector[3][3];
  //dummy slice 1
  slices[0][0] = new PVector(400, 200,-200);
  slices[0][1] = new PVector(300, 400,-200);
  slices[0][2] = new PVector(500, 400,-200);
  //dummy slice 2
  slices[1][0] = new PVector(410, 210,-200);
  slices[1][1] = new PVector(310, 410,-200);
  slices[1][2] = new PVector(510, 410,-200);
  //dummy slice 3
  slices[2][0] = new PVector(420, 220,-200);
  slices[2][1] = new PVector(320, 420,-200);
  slices[2][2] = new PVector(520, 420,-200);
}

void draw() {
  background(255);

  PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  // g may change
  GL gl = pgl.beginGL();  // always use the GL object returned by beginGL

  for(int i = 0 ; i < slices.length; i ++){
    gl.glColor3f(0, .15 * i, 0);
    gl.glBegin(GL.GL_POLYGON);
    for(int j = 0; j < slices[i].length; j++){
      gl.glVertex3f(slices[i][j].x, slices[i][j].y,slices[i][j].z + (zSpacing * i));
    }
    gl.glEnd();
  }
  pgl.endGL();
}

The idea is you loop through each slice, and for each slice your loop through all its points. Obviously slices and the number of 3d vectors inside each slice is up to your data. Speaking of which, where does your data come from ?

If slices is not what your after volTron could come in handy:
volTron http://dm.ncl.ac.uk/joescully/voltronlib/images/s2.jpg

HTH,
George

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文