读取 Lightwave LWO 双星,UV 问题
好的,所以我正在尝试制作 CSHARP Lightwave 3D 模型转换器,将我的 LWO 转换为 Javascript 对象。到目前为止,我已经让这个程序正常运行了,我很高兴。但我在从二进制文件导出 UV 时遇到了麻烦。
这是我的 LWO 二进制文件的参考资料: http://www.gpwiki.org/index.php/LWO
用于测试目的我我使用带有两个三角形、六个点的单个正方形模型。因此,正如您可能已经熟悉的那样,我得到了纹理 UV 块,它在十六进制中看起来像这样(带注释的逗号,并翻译为 Ascii):
[V] [M] [A] [P]
00 00 00 4C
[T] [X] [U] [V]
00 02
[t] [e] [s] [t] [.] [p] [n] [g]
00 00
00 00, 3E FD FD FD, 3E FD FD FD,
00 01, 3F 2A FD FD, 3E FD FD FD,
00 02, 3E FD FD FD, 3F 2A FD FD,
00 03, 3F 2A FD FD, 3E FD FD FD,
00 04, 3F 2A FD FD, 3F 2A FD FD,
00 05, 3E FD FD FD, 3F 2A FD FD
现在,根据我链接的文档,它翻译为以下内容。如果您想自己翻译它,我发现这是一个方便的工具,用于将 32 位十六进制转换为 IEEE 754 单浮点。
http://www.h-schmidt.net/FloatApplet/IEEE754.html
LWO UV 二进制翻译:
VMAP
76
TXUV
2
test.png
0
0, 0.4960784, 0.4960784
1, 0.6679380, 0.4960784
2, 0.4960784, 0.6679380
3, 0.6679380, 0.4960784
4, 0.6679380, 0.6679380
5, 0.4960784, 0.6679380
看,这看起来足够健康,直到您将 UV 位置与 Lightwave 中的实际位置进行比较:
0, 0.3333333, 0.3333333 or (33.33333%)
1, 0.6666667, 0.3333333
2, 0.3333333, 0.6666667
3, 0.6666667, 0.3333333
4, 0.6666667, 0.6666667
5, 0.3333333, 0.6666667
您可以看到,二进制文件并没有那么遥远,但它足以产生所有差异,特别是当意图就是出口数千个这样的虫子。现在我看不出这种差异有什么规律。
我目前的理论是这些数字不是 IEEE754 格式。但所有其他值都是如此,那么为什么这些值会有所不同呢?我有什么遗漏的吗?为了获得更多帮助,这里有一些其他测试值。
Lightwave => Binary
0.00000000 => 0.00000000
0.25000000 => 0.49414062
0.40000000 => 0.49607840
0.50000000 => 0.50000000
0.70000000 => 0.70000000
1.00000000 => 1.97656250
看来有些是正确的,而另一些则……非常错误。感谢您花时间阅读这个问题,我很高兴它很长且充满数字。任何帮助都会很棒!在此处输入代码
Okay, so I'm trying to make CSHARP Lightwave 3D model converter to convert my LWOs into a Javascript object. So far I have the guts of the program working, and I'm please. But I've run into trouble with exporting UVs from the binary file.
This is my reference material for the LWO binary:
http://www.gpwiki.org/index.php/LWO
For testing purpose I'm using single square model with two triangles, with six points. So as you might already be familiar with, I get to the Texture UV chunk which looks like this in HEX (with annotated commas, and Ascii translated):
[V] [M] [A] [P]
00 00 00 4C
[T] [X] [U] [V]
00 02
[t] [e] [s] [t] [.] [p] [n] [g]
00 00
00 00, 3E FD FD FD, 3E FD FD FD,
00 01, 3F 2A FD FD, 3E FD FD FD,
00 02, 3E FD FD FD, 3F 2A FD FD,
00 03, 3F 2A FD FD, 3E FD FD FD,
00 04, 3F 2A FD FD, 3F 2A FD FD,
00 05, 3E FD FD FD, 3F 2A FD FD
Now, according to the documentation I linked about, that translates to the below. If you want to translate this yourself, this is a handy tool, I find, for translating a 32 bit HEX into a IEEE 754 Single float.
http://www.h-schmidt.net/FloatApplet/IEEE754.html
LWO UV binary translated:
VMAP
76
TXUV
2
test.png
0
0, 0.4960784, 0.4960784
1, 0.6679380, 0.4960784
2, 0.4960784, 0.6679380
3, 0.6679380, 0.4960784
4, 0.6679380, 0.6679380
5, 0.4960784, 0.6679380
See, this looks healthy enough until you compare the UV positions to the actual positions in Lightwave:
0, 0.3333333, 0.3333333 or (33.33333%)
1, 0.6666667, 0.3333333
2, 0.3333333, 0.6666667
3, 0.6666667, 0.3333333
4, 0.6666667, 0.6666667
5, 0.3333333, 0.6666667
You can see, the binary file isn't that far off, but it's enough to make all the difference, especially when intension is to export thousands of these buggers. Now I can see no pattern in this discrepency.
My current theory at the moment is that the numbers aren't in IEEE754 format. But all other values are, so why would these be different. Is there something I'm missing? For a little further help, here are some other test values.
Lightwave => Binary
0.00000000 => 0.00000000
0.25000000 => 0.49414062
0.40000000 => 0.49607840
0.50000000 => 0.50000000
0.70000000 => 0.70000000
1.00000000 => 1.97656250
It appears some are correct, and others are just... so very wrong. Thanks for taking the time to read this question, I appreciate that it's very long and dense with numbers. Any help would be fantastic!enter code here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从 http://www.newtek.com/lightwave/developers.php< 获取 Lightwave sdk< /a> .
它包含有关 .lwo 格式的完整文档。
编辑:
Lightwave 将所有数据存储在 Big Endian 中。因此,在将字节解释为浮点数之前,必须先交换字节。
You can get the Lightwave sdk from http://www.newtek.com/lightwave/developers.php .
It includes a complete documentation on the .lwo format.
EDIT:
Lightwave stores all it's data in Big Endian. So you have to swap the bytes before interpreting them as float.