はりうすブログ (のすけのメモ)

湘南にある小さな会社 代表 ”のすけ”のブログです

babylon.js ステップ3 線Lineを使ったいろいろな形状を表示

いろいろな形状シリーズです。

いきましょう!

	//Array of points to construct lines
	var myPoints = [
		new BABYLON.Vector3(0, 0, 0),
		new BABYLON.Vector3(0, 1, 1),
		new BABYLON.Vector3(0, 1, 0)
	];
	
	//Create lines 
	var lines = BABYLON.MeshBuilder.CreateLines("lines", {points: myPoints}, scene); 

BABYLON.Vector3型で繋いでいきます

f:id:hollywis:20200619142450p:plain


Babylon.js Playground

螺旋

f:id:hollywis:20200619142758p:plain

 //Array of points to construct a spiral with lines
 var myPoints = [];

    var deltaTheta = 0.1;
    var deltaY = 0.005;

    var radius = 1;
    var theta = 0;
    var Y = 0;
    for (var i = 0; i<400; i++) {
        myPoints.push(new BABYLON.Vector3(radius * Math.cos(theta), Y, radius * Math.sin(theta)));
        theta += deltaTheta;
        Y += deltaY
    }
	
 //Create lines 
 var lines = BABYLON.MeshBuilder.CreateLines("lines", {points: myPoints}, scene); 

線400個を螺旋状に繋いでグルグルな物も作れます

まとめ

線です。

簡単です。螺旋を描くには座標計算にオイラー角が必要なので、その辺りは難しいですが

線自体は簡単ですね。

hollywis.hatenablog.com