javascript - 如何在 three.js 中修复此几何图形
问题描述
我正在尝试将在单独的库中生成的几何 canvas2d 命令转换为three.js webgl 输出。我已经剪切了一个示例,并且在一个小提琴和相应的three.js 小提琴中有一个canvas2d 输出。如您所见,three.js 输出不正确。所以我必须修改生成命令的库或添加/删除命令或更改 three.js 参数本身。请问有人可以帮我修复这个例子吗?
这是canvas2d小提琴: https ://jsfiddle.net/onifs/a1L87mhb/2/
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
这里是three.js之一: https ://jsfiddle.net/onifs/s6xn0obu/13/
constructPathShape = new THREE.Shape();
请点击“更多”按钮数次查看形状是如何构建的。
TIA
解决方案
主轮廓完成后,您需要填充Shape.holes
你的小提琴的固定叉可以在这里找到:https ://jsfiddle.net/mmalex/6khnx2zy/
...
command[i++] = "constructPathShape.closePath();"; //outer contour is complete
command[i++] = "{ let hole = new THREE.Shape(); "
+ " hole.autoClose = false; "
+ " constructPathShape.holes.push(hole); "
+ " constructPathShape.holes[0].moveTo( -39.196, -59.186); "
+ "}";
// !!! IMPORTANT: starting from now address .holes[0]
command[i++] = "constructPathShape.holes[0].bezierCurveTo( -38.412,-47.08,-34.342,-37.412,-26.98,-30.181);";
command[i++] = "constructPathShape.holes[0].bezierCurveTo( -19.62,-22.952,-10.54,-19.337,0.261,-19.337);";
command[i++] = "constructPathShape.holes[0].bezierCurveTo( 12.194,-19.337,21.905,-23.867,29.397,-32.925);";
command[i++] = "constructPathShape.holes[0].bezierCurveTo( 34.274,-38.761,37.236,-47.515,38.282,-59.186);";
command[i++] = "constructPathShape.holes[0].lineTo( -39.196, -59.186);";
command[i++] = "constructPathShape.holes[0].closePath();";
command[i++] = " \/* we're done *\/ ;";
推荐阅读
- linux - 使用 GNU AS (GAS) .intel_syntax 将静态地址放入寄存器?
- if-statement - 运行 if 语句并将结果存储在向量中
- javascript - JavaScript 表单中的边框颜色不会覆盖
- html - mPDF 图像以裁剪且无失真的方式覆盖页面
- css - 悬停在另一个 div 上时如何调整 2 个 div 的大小?
- java - 图形面板调整大小
- java - 升级到 gradle 4.4 和 gradle build tools 版本 3.1.2 后在文件中出现红线
- sql - 如何使用 RODBC 将数据框保存到具有在数据库中生成的主键的表中
- vhdl - 使用 VHDL 的 PWM 控制 LED
- python - 如何在 Python 中再次使用以前匹配的正则表达式?