我正在寻找一种在Chrome浏览器中显示带有颜色映射的网格物体的方法,因此我尝试了x3dom
和indexedFaceSet
。我假设有一种方法可以为顶点分配颜色,以便对脸部的颜色进行插值,或者至少我应该能够为每个脸部分配不同的恒定颜色。看来,无论我尝试什么,我都只能显示脸部线条,并且定义的颜色无效。目前,我有这个html代码:
<html>
<head>
<script type='text/javascript' src='http://www.x3dom.org/download/x3dom.js'> </script>
<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/download/x3dom.css'></link>
</head>
<body>
<X3D width='600px' height='400px' showLog='true'>
<Scene>
<Shape>
<IndexedFaceSet coordIndex='0 1 2 -1, 1 2 3 -1' colorPerVertex='true' solid='false'>
<Coordinate point='0 0 0, 1 0 0, 0 1 0, 1 1 0'/>
<Color color='0 1 0, 1 0 0, 0 0 1, 0 1 0'/>
</IndexedFaceSet>
</Shape>
</Scene>
</X3D>
</body>
</html>
我想,我要么丢失了一些非常简单的东西,要么x3dom无法在我的计算机上正常工作。
可能的解决方案是使用具有以下内容的。xhtml格式(而不是。html):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<link rel='stylesheet' type='text/css' href='x3dom.css'/>
</head>
<body>
<X3D width='600px' height='526px'>
<Scene>
<Transform>
<Shape>
<IndexedFaceSet solid='false' coordIndex='0 1 2 -1'>
<Coordinate point='1 0 0 0 2 0 0 0 3'/>
<Color color='1 0 0 0 1 0 0 0 1'/>
</IndexedFaceSet>
</Shape>
</Transform>
</Scene>
</X3D>
<script type="text/javascript" src='http://www.x3dom.org/download/x3dom.js'></script>
</body>
</html>
此解决方案的创建将this example简化为我要完成的工作的“最小示例”。
有效。正如Tomas所说,我们必须使用。xhtml格式,而不是。html。请参阅下面的答案,以示例说明如何使用字段[[colorIndex和color用IndexedFaceSet
绘制金字塔<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<script type="text/javascript" src='http://www.x3dom.org/download/x3dom.js'></script>
<link rel='stylesheet' type='text/css' href='x3dom.css'/>
</head>
<body>
<X3D width='50%' height='50%'>
<Scene>
<Shape>
<Appearance><Material specularColor='1 1 1' shininess='0.9' /></Appearance>
<IndexedFaceSet solid='false' creaseAngle='0.000' colorPerVertex='false' coordIndex='0 1 2 -1 0 1 3 -1 0 2 3 -1 1 2 3 -1' colorIndex='0 1 0 2' >
<Coordinate point='1 0 0 0 1 0 0 0 1 0 0 0 ' />
<Color color='1. 0. 0. 0. 1. 0. 0. 0. 1.' />
</IndexedFaceSet>
</Shape>
</Scene>
</X3D>
</body>
</html>