Papervision3Dをちゃんと勉強しようかな。今までPlaneとかCubeとか基本的なクラスしか使ったことなかったし。
Vertex3Dとは3D空間における3次元頂点のこと。引数はx、y、zの各座標。ラインを描画するには、開始頂点と終了頂点を線でつなぐ、つまりlineToと一緒でz座標が増えただけ。描画の前にLines3DインスタンスをシーンにaddChildしておくこと。Lines3DはLine3Dを描画する入れ物。複数形なので最初にコード見たとき紛らわしい。
package
{
import org.papervision3d.core.geom.Lines3D;
import org.papervision3d.core.geom.renderables.Line3D;
import org.papervision3d.core.geom.renderables.Vertex3D;
import org.papervision3d.materials.special.LineMaterial;
import org.papervision3d.view.BasicView;
import flash.events.Event;
public class Main extends BasicView
{
private var lines3D:Lines3D;
//------------------------------
// コンストラクタ
//------------------------------
public function Main()
{
var line:Line3D;
var startV:Vertex3D;
var endV:Vertex3D;
var lm:LineMaterial = new LineMaterial(0xFF66CC);
//-----[ラインを入れるラッパークラス]
lines3D = new Lines3D();
scene.addChild(lines3D);
//-----[ラインの各頂点位置]
var vertexAry:Array = [
{ x:0, y:0, z:0 },
{ x:50, y:50, z:0 },
{ x:50, y:100, z:100 },
{ x:0, y:150, z:100 },
{ x:0, y:200, z:0 },
{ x:200, y:250, z:0 },
{ x:200, y:300, z:400 },
{ x:0, y:350, z:400 },
{ x:0, y:400, z:0 },
{ x:400, y:450, z:0 },
{ x:400, y:500, z:800 },
{ x:0, y:550, z:800 },
]
//-----[ラインの生成]
for (var i:uint = 1; i < vertexAry.length; i++)
{
startV = new Vertex3D(vertexAry[i - 1].x, vertexAry[i - 1].y, vertexAry[i - 1].z);
endV = new Vertex3D(vertexAry[i].x, vertexAry[i].y, vertexAry[i].z);
line = new Line3D(lines3D, lm, 2, startV, endV);
lines3D.addLine(line);
}
//-----[カメラの設定]
camera.y = 300;
camera.target.y = 300;
//-----[レンダリング開始]
startRendering();
}
//------------------------------
// レンダリング
//------------------------------
protected override function onRenderTick(e:Event = null):void
{
lines3D.yaw((mouseX - (stage.stageWidth / 2)) / (stage.width / 2) * 5);
super.onRenderTick(e);
}
}
}