简体   繁体   English

使用JavaScript建模3D多面体

[英]Using JavaScript to model 3D polyhedra

Is there a JavaScript library that models 3D polyhedra using the canvas tag or SVG? 是否有使用canvas标签或SVG对3D多面体进行建模的JavaScript库? Say I wanted to produce renderings of the Platonic solids , how would I best achieve this? 假设我想制作柏拉图实体的渲染图,我最好如何实现这一目标? FWIW, I'm only concerned with WebKit-based web browsers such as Safari and Chrome. FWIW,我只关注基于WebKit的Web浏览器,例如Safari和Chrome。

I've seen this cool demo of how to render 3D triangles , but how might I extend it to polyhedra with an arbitrary number of sides? 我已经看过如何渲染3D三角形的这个很酷的演示,但是如何将它扩展到具有任意数量边的多面体?

Take a look at this library: SVG-VML-3D 看看这个库: SVG-VML-3D

It uses SVG and falls back to VML on MSIE. 它使用SVG并在MSIE上回退到VML。 They do have a demo with platonic solids. 他们有一个带有柏拉图固体的演示。 I don't have a Webkit-browser handy, but presume it should work there as well. 我没有Webkit浏览器,但是假设它也应该在那里工作。

Not a direct answer to your question, but seeing as you mentioned WebKit-only I thought I'd point out the new 3D CSS Transform support which was added to webkit pretty recently. 不是你的问题的直接答案,但看到你提到WebKit,我认为我会指出最近添加到webkit的新的3D CSS Transform支持。 This allows you to do what you want without using any Javascript. 这允许您在不使用任何Javascript的情况下执行您想要的操作。 I've not seen an example of 3D polyhedra, but there are examples of cubes etc out there - for example here . 我没有看到3D多面体的例子,但是有一些立方体等的例子 - 例如这里

There's a slightly more complex demo here which has a ring of rectangles. 这里有一个稍微复杂的演示它有一个矩形环。 For a real taste of what you could do (although this does use Javascript for animation) - see the Snow Stack demo. 要真正体验你能做什么(尽管这确实使用Javascript进行动画制作) - 请参阅Snow Stack演示。

Most 3D libraries generalize triangles. 大多数3D库概括了三角形。 If you want a polygon with more than 3 sides, you subdivide it into triangles and draw those triangles. 如果想要一个具有3个以上边的多边形,可以将其细分为三角形并绘制这些三角形。 If you're interested in just the platonic solids, then you're going to have a pretty easy time, because you can easily get a triangluation of each face by first averaging the vertices of each face, and then using that center and two adjacent vertices of the face to give you a triangularization. 如果你只对柏拉图固体感兴趣,那么你将有一个相当容易的时间,因为你可以通过首先平均每个面的顶点,然后使用该中心和两个相邻的方法轻松获得每个面的三角形脸的顶点给你一个三角化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM