0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

plunkerでopenjscad その12

Posted at

概要

plunkerでopenjscadやってみる。
練習問題やってみた。

練習問題

MQOをパースして、描画せよ。

写真

image.png

サンプルコード

function main() {
	var mqo = 
"Metasequoia Document\n" +
"Format Text Ver 1.0\n" +
"\n" +
"Scene {\n" +
"  pos 0.0000 0.0000 1500.0000\n" +
"  lookat 0.0000 0.0000 0.0000\n" +
"  head 3.7864\n" +
"  pich 0.2392\n" +
"  ortho 0\n" +
"  zoom2 5.0000\n" +
"  amb 0.250 0.250 0.250\n" +
"}\n" +
"Material 2 {\n" +
'  "mat1" col(1.000 0.000 0.000 1.000) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00)\n' +
'  "mat2" col(1.000 0.647 0.000 1.000) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00)\n' +
"}\n" +
'Object "obj1" {\n' +
"  visible 15\n" +
"  locking 0\n" +
"  shading 0\n" +
"  facet 59.5\n" +
"  color 0.898 0.498 0.698\n" +
"  color_type 0\n" +
"  vertex 8 {\n" +
"    -100.0000 100.0000 100.0000\n" +
"    -100.0000 -100.0000 100.0000\n" +
"     100.0000 100.0000 100.0000\n" +
"     100.0000 -100.0000 100.0000\n" +
"     100.0000 100.0000 -100.0000\n" +
"     100.0000 -100.0000 -100.0000\n" +
"    -100.0000 100.0000 -100.0000\n" +
"    -100.0000 -100.0000 -100.0000\n" +
"  }\n" +
"  face 6 {\n" +
"    4 V(0 2 3 1) M(0) UV(0.00000 0.00000 1.00000 0.00000 1.00000 1.00000 0.00000 1.00000)\n" +
"    4 V(2 4 5 3) M(1) UV(0.00000 0.00000 1.00000 0.00000 1.00000 1.00000 0.00000 1.00000)\n" +
"    4 V(4 6 7 5) M(0) UV(0.00000 0.00000 1.00000 0.00000 1.00000 1.00000 0.00000 1.00000)\n" +
"    4 V(6 0 1 7) M(0) UV(0.00000 0.00000 1.00000 0.00000 1.00000 1.00000 0.00000 1.00000)\n" +
"    4 V(6 4 2 0) M(0) UV(0.00000 0.00000 1.00000 0.00000 1.00000 1.00000 0.00000 1.00000)\n" +
"    4 V(1 3 5 7) M(0) UV(0.00000 0.00000 1.00000 0.00000 1.00000 1.00000 0.00000 1.00000)\n" +
"  }\n" +
"}\n" +
"Eof";
	var points = [];
	var faces = [];
  var textArray = mqo.split(/\r\n|\r|\n/);
	for (var i = 0; i < textArray.length; i++)
	{
		var line = textArray[i];
		if (line.indexOf('    4') === 0)
		{
			line = line.replace('    4 V(', '');
			var tmp = line.replace(')', '');
			var p = tmp.split(' '); 
			faces.push([p[0], p[1], p[2]]);
			faces.push([p[0], p[2], p[3]]);
		}
		else if (line.indexOf('    ') === 0)
		{
			line = line.trim();
			var tmp = line.split(' ');
			points.push([tmp[0], tmp[1], tmp[2]]);
		}
	}
	return CSG.polyhedron({
		points: points,
		faces: faces
	});
}

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?