问题
I load a glb model in Three.js generated in SketchUp. The file can be found here https://www.graviditetsberegner.dk/bpnew.skp
The model contains a group called text with a mesh. I want to display a texture containing text here. I use the below code:
var modelLoader = new THREE.GLTFLoader();
modelLoader.load("https://www.graviditetsberegner.dk/bpnew.glb", function (gltf) {
model = gltf.scene.clone();
model.scale.set(50,50,50)
scene.add(model);
//Use canvas to draw texture and add it to the model group Text
var textModelMesh = FindMeshWithNameInModel(model, "Text");
var textTexture = CreateCanvasTexture("This is a test");
textTexture.wrapS = THREE.RepeatWrapping;
textTexture.wrapT = THREE.RepeatWrapping;
textModelMesh.material.map = textTexture;
I have two issues with the code:
- The text is mirrored. In other formats such as dae, the text is not mirrored
- The text is only displayed when I set wrapS and wrapT to RepeatWrapping. However, the texture used in SketchUp should be similar to the dimensions of the generated texture in the canvas.
How can I fix these issues?
A fiddle showing the problem: https://jsfiddle.net/Lgmds9ce/2/
回答1:
The text is mirrored. In other formats such as dae, the text is not mirrored
As mentioned in the official documentation for THREE.GLTFLoader
you have to set Texture.flipY
to false
if you manually replace a texture.
The text is only displayed when I set wrapS and wrapT to RepeatWrapping. However, the texture used in SketchUp should be similar to the dimensions of the generated texture in the canvas.
The texture from the asset has also set Texture.wrapS
and Texture.wrapT
to THREE.RepeatWrapping
.
Updated fiddle: https://jsfiddle.net/d12t6p5q/1/
three.js R105
来源:https://stackoverflow.com/questions/56443872/assigned-texture-to-glb-model-in-three-js-is-reversed-and-only-working-with-thre