[英]three.js map mesh.geometry.attributes.uv
I am currently working on a 3D configurator.我目前正在研究 3D 配置器。 So I should be able to import a logo on a FBX object, which normally already have UV coordinates.
所以我应该能够在 FBX 对象上导入徽标,该对象通常已经具有 UV 坐标。 The problem is : I am struggling since 3 days ago, trying to import a texture on a mesh but I can't map it using his UVs coordinates.
问题是:我从 3 天前开始挣扎,试图在网格上导入纹理,但我无法使用他的 UV 坐标映射它。
So, I have a texture with a logo.所以,我有一个带有标志的纹理。
When I map it on a simple Cube, no problem, it is working :当我将它映射到一个简单的立方体上时,没问题,它正在工作:
But when I try to apply the same texture to my mesh :但是当我尝试将相同的纹理应用于我的网格时:
The texture is cropped.纹理被裁剪。 So I've been looking inside the mesh json tree and I found it :
所以我一直在寻找网格 json 树的内部,我找到了它:
So there are uv coordinates, but it seems different from my cube because, when I look to his json, I don't find the same tree which is (on the cube) :所以有 uv 坐标,但它似乎与我的立方体不同,因为当我查看他的 json 时,我没有找到(在立方体上)相同的树:
And finally, this is my code :最后,这是我的代码:
if(myMesh.name == 'Logo'){
// Texture
var texture = new THREE.TextureLoader().load('img/logoTesla_Verre_green.jpg', function(){
texture.needUpdate = true;
// Material
var material = new THREE.MeshLambertMaterial( {map: texture, morphTargets: true} );
material.needUpdate = true;
// Geometry Cube
var geometry = new THREE.BoxGeometry( 40, 40, 40 );
// Cube
var cube = new THREE.Mesh( geometry, material);
scene.add(cube);
// Duplicate logo mesh for testing
var newGeometry = myMesh.geometry;
var newMesh = new THREE.Mesh( newGeometry, material);
newMesh.position.y = 100;
newMesh.geometry.uvsNeedUpdate = true;
scene.add(newMesh);
});
}
My question is : Should I use the geometry.attributes.uv object to map my texture ?我的问题是:我应该使用 geometry.attributes.uv 对象来映射我的纹理吗? If yes, how to do that ?
如果是,该怎么做?
Or should I convert these UV coordinates to a geometry.faceVertexUvs ???或者我应该将这些 UV 坐标转换为 geometry.faceVertexUvs ???
Please, help me, I am totally lost :)请帮帮我,我完全迷路了:)
Nevermind, it has been solved by exporting the .fbx again.没关系,已经通过再次导出.fbx 解决了。 Now the mapping is working fine !
现在映射工作正常!
But I don't know why...但是不知道为什么...
Thank you for your question and answer.感谢您的提问和回答。 I was having the same problem where my custom FBX I imported was only taking the bottom left pixel of the canvas as the color for the whole mesh.
我遇到了同样的问题,我导入的自定义 FBX 仅将画布的左下角像素作为整个网格的颜色。 (I was using
texture = new THREE.CanvasTexture(ctx.canvas);
to get my texture). (我使用
texture = new THREE.CanvasTexture(ctx.canvas);
来获取我的纹理)。
The issue for me was that the FBX had no UV mapping!我的问题是 FBX 没有 UV 贴图! How I solved it was I imported the fbx to maya, opened up the UV editor (under the modeling menu mode got to UV->UV editor ) then in the UV editor there was a Create section and I hit one of those options (i chose cylinder) and then exported it with the default fbx settings.
我的解决方法是将 fbx 导入到 Maya,打开 UV 编辑器(在建模菜单模式下进入 UV->UV 编辑器)然后在 UV 编辑器中有一个创建部分,我点击了其中一个选项(我选择圆柱体),然后使用默认的 fbx 设置将其导出。 I am very grateful this worked.
我非常感谢这有效。
You can see the result of using a canvas context as a custom FBX texture here: www.algorat.club/sweater您可以在此处查看使用画布上下文作为自定义 FBX 纹理的结果: www.algorat.club/sweater
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.