Last active
December 6, 2019 00:44
-
-
Save TakashiYoshinaga/a583d5b3de4edf7bcf713d6571db5d86 to your computer and use it in GitHub Desktop.
Implementation of mesh initialization for drawing point cloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Meshを用いてPointCloudを描画する準備をする | |
private void InitMesh() | |
{ | |
//Depth画像の横幅と縦幅を取得し、全点数を算出 | |
int width = kinect.GetCalibration().DepthCameraCalibration.ResolutionWidth; | |
int height = kinect.GetCalibration().DepthCameraCalibration.ResolutionHeight; | |
num = width * height; | |
//meshをインスタンス化 | |
mesh = new Mesh(); | |
//65535点以上を描画するため下記を記述 | |
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; | |
//Depth画像の総ピクセル数分の頂点や色の記憶領域を確保 | |
vertices = new Vector3[num]; | |
colors = new Color32[num]; | |
indices = new int[num]; | |
//描画する点の配列番号を記録。(全ての点を描画) | |
for(int i = 0; i < num; i++) | |
{ | |
indices[i] = i; | |
} | |
//点の座標や色、描画する点のリストをmeshに渡す | |
mesh.vertices = vertices; | |
mesh.colors32 = colors; | |
mesh.SetIndices(indices, MeshTopology.Points, 0); | |
//メッシュをこのスクリプトが貼られているオブジェクトのMashFilterに適用 | |
gameObject.GetComponent<MeshFilter>().mesh = mesh; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment