JDoe
JDoe

Reputation: 96

How to apply a texture on a mesh exported from blender as wrl and imported into threejs using VRMLLoader

I have exported a simple box mesh from blender as wrl. I have "smart uv unwrap"ed the mesh also. I am using this mesh only for it's geometry and am applying material through threejs. I am then binding a texture with the imported mesh, and i am also setting the needsUpdate property of material (MeshPhongMaterial) to true.

The result is as follows :

enter image description here

The applied texture :

enter image description here

The code excerpts are as follows :

function generateCustomTHREEMeshFromWRL(name) {
    return vrmlLoader.parse(getResource(name).content).children[0]
    //the getResource(name).content returns the entire wrl file content
}
mesh = generateCustomTHREEMeshFromWRL('unwrapped.wrl')  
mesh.material.map = textureLoader.load('lavatile.jpg')
mesh.material.needsUpdate = true;
scene.add(mesh)

The WRL file is as follows :

#VRML V2.0 utf8
#modeled using blender3d http://blender.org

# 'Cube'
Shape {
    appearance Appearance {
        material Material {
        }
    }
    geometry IndexedFaceSet {
        coord Coordinate {
            point [ -1.000000 -1.000000 1.000000 -1.000000 -1.000000 -1.000000 1.000000 -1.000000 -1.000000 1.000000 -1.000000 1.000000 -1.000000 1.000000 0.999999 -0.999999 1.000000 -1.000001 1.000000 1.000000 -1.000000 1.000000 1.000000 1.000000 ]
        }
        colorPerVertex FALSE
        color Color {
            color [ 0.80 0.80 0.80 ]
        }
        colorIndex [ 0 0 0 0 0 0 0 0 0 0 0 0 ]
        coordIndex [ 1 3 0 -1 7 5 4 -1 4 1 0 -1 5 2 1 -1 2 7 3 -1 0 7 4 -1 1 2 3 -1 7 6 5 -1 4 5 1 -1 5 6 2 -1 2 6 7 -1 0 3 7 -1 ]
    }
}

This is a glimpse of the actions I am performing in blender enter image description here

Upvotes: 0

Views: 371

Answers (0)

Related Questions