技術力をスコア化して市場価値をチェックしてみませんか?PR

ブログやSNSのアウトプットをAIが分析。技術力の順位を算出!自分の市場価値を測ってみませんか?

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 その10

Last updated at Posted at 2023-10-14

概要

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

練習問題

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

写真

image.png

サンプルコード

function main() {
	var stl = 
"	solid square-ascii.SLDPRT\n" +
"   facet normal 0.000000e+00 0.000000e+00 -1.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 0.000000e+00 2.500000e+01 0.000000e+00\n" +
"		 vertex 2.500000e+01 2.500000e+01 0.000000e+00\n" +
"		 vertex 0.000000e+00 0.000000e+00 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal 0.000000e+00 -0.000000e+00 -1.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 2.500000e+01 2.500000e+01 0.000000e+00\n" +
"		 vertex 2.500000e+01 0.000000e+00 0.000000e+00\n" +
"		 vertex 0.000000e+00 0.000000e+00 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal -1.000000e+00 0.000000e+00 0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 0.000000e+00 0.000000e+00 2.500000e+01\n" +
"		 vertex 0.000000e+00 2.500000e+01 0.000000e+00\n" +
"		 vertex 0.000000e+00 0.000000e+00 0.000000e+00\n" +
"	  endloop\n" +
"  endfacet\n" +
"   facet normal -0.000000e+00 -1.000000e+00 0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 2.500000e+01 0.000000e+00 2.500000e+01\n" +
"		 vertex 0.000000e+00 0.000000e+00 2.500000e+01\n" +
"		 vertex 0.000000e+00 0.000000e+00 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal 0.000000e+00 -1.000000e+00 0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 2.500000e+01 0.000000e+00 0.000000e+00\n" +
"		 vertex 2.500000e+01 0.000000e+00 2.500000e+01\n" +
"		 vertex 0.000000e+00 0.000000e+00 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal 1.000000e+00 0.000000e+00 -0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 2.500000e+01 2.500000e+01 0.000000e+00\n" +
"		 vertex 2.500000e+01 2.500000e+01 2.500000e+01\n" +
"		 vertex 2.500000e+01 0.000000e+00 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal 1.000000e+00 0.000000e+00 0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 2.500000e+01 2.500000e+01 2.500000e+01\n" +
"		 vertex 2.500000e+01 0.000000e+00 2.500000e+01\n" +
"		 vertex 2.500000e+01 0.000000e+00 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal -1.000000e+00 -0.000000e+00 -0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 0.000000e+00 2.500000e+01 2.500000e+01\n" +
"		 vertex 0.000000e+00 2.500000e+01 0.000000e+00\n" +
"		 vertex 0.000000e+00 0.000000e+00 2.500000e+01\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal 0.000000e+00 0.000000e+00 1.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 2.500000e+01 0.000000e+00 2.500000e+01\n" +
"		 vertex 0.000000e+00 2.500000e+01 2.500000e+01\n" +
"		 vertex 0.000000e+00 0.000000e+00 2.500000e+01\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal 0.000000e+00 0.000000e+00 1.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 2.500000e+01 2.500000e+01 2.500000e+01\n" +
"		 vertex 0.000000e+00 2.500000e+01 2.500000e+01\n" +
"		 vertex 2.500000e+01 0.000000e+00 2.500000e+01\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal 0.000000e+00 1.000000e+00 0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 0.000000e+00 2.500000e+01 2.500000e+01\n" +
"		 vertex 2.500000e+01 2.500000e+01 0.000000e+00\n" +
"		 vertex 0.000000e+00 2.500000e+01 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"   facet normal -0.000000e+00 1.000000e+00 0.000000e+00\n" +
"	  outer loop\n" +
"		 vertex 0.000000e+00 2.500000e+01 2.500000e+01\n" +
"		 vertex 2.500000e+01 2.500000e+01 2.500000e+01\n" +
"		 vertex 2.500000e+01 2.500000e+01 0.000000e+00\n" +
"	  endloop\n" +
"   endfacet\n" +
"endsolid";
	var points = []; 
	var faces = [];
	var t = 0;
	var vertexes = stl.match(/facet\s+normal\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+outer\s+loop\s+vertex\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+vertex\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+vertex\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+endloop\s+endfacet/g);
	vertexes.forEach(function(vert) {
		vert.match(/vertex\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s+([-+]?\b(?:[0-9]*\.)?[0-9]+(?:[eE][-+]?[0-9]+)?\b)\s/g).forEach(function(vertex, i) {
			var tempVertex = vertex.replace('vertex', '').match(/[-+]?[0-9]*\.?[0-9]+/g);
			points.push([tempVertex[0], tempVertex[2], tempVertex[4]]);
		});
    faces.push([t, t + 1, t + 2]);
		t = t + 3;
	})
	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

Comments

No comments

Let's comment your feelings that are more than good

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?