2

2 つの関数によって生成されたボリュームの 3D モデルを作成しています。1 つはベース (x 軸の交点) として、もう 1 つはボリュームの高さです。そのメッシュを作成し、すべてのメッシュを一緒に追加します。ただし、メッシュを一緒に追加する方法がわかりません。

これが私のメッシュ作成者です:

 private TriangleMesh createVolume(double start, double end, double numSteps, PolynomialFunction base, PolynomialFunction height) {
    TriangleMesh m = new TriangleMesh();

    double stepSize = (end-start)/numSteps;

    for(double i = start; i < end; i += stepSize) {

        double x = i;
        double x2 = x+stepSize;
        double gx = height.value(x);
        double gx2 = height.value(x2);
        double fx = base.value(x);
        double fx2 = base.value(x2);


        TriangleMesh t = createVolumeSection(x,x2,gx,gx2,fx,fx2);
        m.getPoints().addAll(t.getPoints());
        m.getTexCoords().addAll(t.getTexCoords());
        m.getFaces().addAll(t.getFaces());
    }

    return m;
}


private TriangleMesh createVolumeSection(double xVal, double x2Val, double gxVal, double gx2Val,
                                         double fxVal, double fx2Val){
    TriangleMesh m = new TriangleMesh();
    float x = ((float)xVal) ;
    float x2 = ((float)x2Val);
    float gx = ((float)gxVal);
    float gx2 = ((float)gx2Val);
    float fx = ((float)fxVal);
    float fx2 = ((float)fx2Val);

    //create Points
    m.getPoints().addAll(
            x,  0,  0,      // A = 0
            x,  0,  gx,     // B = 1
            x2, 0,  0,      // C = 2
            x2, 0,  gx2,    // D = 3
            x,  fx, 0,      // E = 4
            x,  fx, gx,     // F = 5
            x2, fx2,0,      // G = 6
            x2, fx2,gx2     // H = 7
    );

    m.getTexCoords().addAll(0,0);

    m.getFaces().addAll(
            0 , 0 , 1 , 0 , 3 , 0 ,     // A-B-D
            0 , 0 , 3 , 0 , 2 , 0 ,     // A-D-C
            0 , 0 , 2 , 0 , 6 , 0 ,     // A-C-G
            0 , 0 , 6 , 0 , 4 , 0 ,     // A-G-E
            0 , 0 , 4 , 0 , 1 , 0 ,     // A-E-B
            1 , 0 , 4 , 0 , 5 , 0 ,     // B-E-F
            1 , 0 , 5 , 0 , 7 , 0 ,     // B-F-H
            1 , 0 , 7 , 0 , 3 , 0 ,     // B-H-D
            3 , 0 , 7 , 0 , 6 , 0 ,     // D-H-G
            3 , 0 , 6 , 0 , 2 , 0 ,     // D-G-C
            6 , 0 , 7 , 0 , 5 , 0 ,     // G-H-F
            6 , 0 , 5 , 0 , 4 , 0       // G-F-E
    );

    return m ;
}

これは、一連の直角台形プリズムを作成することになっていますが、一連の最初のメッシュのみを描画することになります。

誰でも助けることができますか?

前もって感謝します。

4

1 に答える 1

0

あなたのアプローチはほぼ正しいですが、面配列の情報の更新に失敗しています。

ボリューム セクションを追加するたびに、新しい頂点を最終メッシュに追加するため、面配列の頂点インデックスはそれに応じてシフトする必要があります。そのために、n-1 ボリュームに追加された合計ポイントのカウンターを保持します。

private int points=0;

private TriangleMesh createVolume(double start, double end, double numSteps, Function<Number,Number> base, Function<Number,Number> height) {
    ...
    TriangleMesh t = createVolumeSection(x,x2,gx,gx2,fx,fx2);
    m.getPoints().addAll(t.getPoints());
    points=m.getPoints().size()/3;
    ...
}

次に、faces 配列を変更します。

private TriangleMesh createVolumeSection(double xVal, double x2Val, double gxVal, double gx2Val,
                                         double fxVal, double fx2Val){
    TriangleMesh m = new TriangleMesh();
    ...
    m.getFaces().addAll(
            points+0 , 0 , points+1 , 0 , points+3 , 0 ,     // A-B-D
            points+0 , 0 , points+3 , 0 , points+2 , 0 ,     // A-D-C
            points+0 , 0 , points+2 , 0 , points+6 , 0 ,     // A-C-G
            points+0 , 0 , points+6 , 0 , points+4 , 0 ,     // A-G-E
            points+0 , 0 , points+4 , 0 , points+1 , 0 ,     // A-E-B
            points+1 , 0 , points+4 , 0 , points+5 , 0 ,     // B-E-F
            points+1 , 0 , points+5 , 0 , points+7 , 0 ,     // B-F-H
            points+1 , 0 , points+7 , 0 , points+3 , 0 ,     // B-H-D
            points+3 , 0 , points+7 , 0 , points+6 , 0 ,     // D-H-G
            points+3 , 0 , points+6 , 0 , points+2 , 0 ,     // D-G-C
            points+6 , 0 , points+7 , 0 , points+5 , 0 ,     // G-H-F
            points+6 , 0 , points+5 , 0 , points+4 , 0       // G-F-E
    );

    return m ;
}
于 2015-05-19T19:27:04.023 に答える