Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ThreeJS: Some material texture faces / triangles not rendering

Tags:

three.js

I have a .obj and .mtl which load textures from .tga files. This all seems to work / look fine in 3D modeling software, but when loaded with three.js (THREE.WebGLRenderer({ antialias: true })) some of the object's children, (specifically between the knees and the calves, but not, for example, the pockets and legs), seem to have a transparent jagged gap / empty triangles.

(Tried turning on antialiasing, changing the overdraw value, turning off transparency, etc.)

Loader function:

threejsHelper.helpers.loadObject('objects/pants/MaleBaggyPants.obj', 'objects/pants/MaleBaggyPants.mtl', {
    blinn1SG: (new THREE.MeshPhongMaterial({ color: 0xffffff, transparent: false, opacity: 1.0, overdraw: 0.5, map: threejsHelper.helpers.loadTexture(app.manager, 'objects/pants/button.tga') })),
    blinn2SG: (new THREE.MeshPhongMaterial({ color: 0xffffff, transparent: false, opacity: 1.0, overdraw: 0.5, map: threejsHelper.helpers.loadTexture(app.manager, 'objects/pants/back.tga') })),
    blinn4SG: (new THREE.MeshPhongMaterial({ color: 0xffffff, transparent: false, opacity: 1.0, overdraw: 0.5, map: threejsHelper.helpers.loadTexture(app.manager, 'objects/pants/front.tga') })),
    blinn5SG: (new THREE.MeshPhongMaterial({ color: 0xffffff, transparent: false, opacity: 1.0, overdraw: 0.5, map: threejsHelper.helpers.loadTexture(app.manager, 'objects/pants/pocket.tga') })),
    blinn6SG: (new THREE.MeshPhongMaterial({ color: 0xffffff, transparent: false, opacity: 1.0, overdraw: 0.5, map: threejsHelper.helpers.loadTexture(app.manager, 'objects/pants/back.tga') })),
    blinn7SG: (new THREE.MeshPhongMaterial({ color: 0xffffff, transparent: false, opacity: 1.0, overdraw: 0.5, map: threejsHelper.helpers.loadTexture(app.manager, 'objects/pants/front.tga') }))
}, function (object) {
    object.rotation.x = (-90*Math.PI/180);
    object.rotation.z = (-90*Math.PI/180);
    app.scene.add(object);
    app.ready = true;
});

Helper functions:

...
loadTexture: function (manager, path) {
    var texture;
    if (path.split('.').pop() == 'tga') {
        var loader = new THREE.TGALoader();
        texture = loader.load(path);
    } else {
        texture = new THREE.Texture();
        var loader = new THREE.ImageLoader(manager);
        loader.load(path, function (image) {
            texture.image = image;
            texture.needsUpdate = true;
        });
    }
    return texture;
},
loadMaterial: function (mtlPath, textures, complete) {
    var loader = new THREE.MTLLoader();
    loader.load(mtlPath, function (materials) {
        materials.preload();
        if (!!materials.materials) {
            for (var key in materials.materials) {
                if (key in textures) {
                    materials.materials[key] = textures[key];
                }
            }
        }
        complete(materials);
    });
},
loadObject: function (objPath, mtlPath, textures, complete) {
    app.helpers.loadMaterial(mtlPath, textures, function (materials) {
        var loader = new THREE.OBJLoader();
        loader.setMaterials(materials);
        loader.load(objPath, function (object) {
            complete(object);
        });
    });
},
...

1 2 3

like image 953
Matisse VerDuyn Avatar asked Aug 24 '26 16:08

Matisse VerDuyn


1 Answers

You seem to have extra vertices along the seem on both the objects which I think will screw with the triangulation.
Remove these vertices that are not needed and I'm 99% sure it will fix your problem.

extra vertices

I also noticed the model is at a very small scale.

like image 195
2pha Avatar answered Aug 28 '26 20:08

2pha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!