Importing Blender 3D Model with Texture to Three.js

Three.js is the de-facto standard when working with 3D in the browser. It’s great with creating and manipulating 3D objects, but it only ships with standard geometry (cubes, spheres, etc.), so at some point, you ‘ll want to import your own 3D model to Threejs.

I’ll walk you through the process of exporting the model in Blender to a Threejs compatible JSON format, and importing it correctly in Threejs with its texture.

I like to bundle several models directly within Blender to a single one. So if you have a castle consisting of individual models — the outer wall, and two towers — join them into a single object. In Blender, you select all the objects and press CTRL + J (Join). I also like to use a single texture map that I subdivide for each previously individual model, each quadrant gets its own model. This has the benefit that we can export a single object in Blender, and thus only need to load one file for the geometry, and one file for the texture image later in Threejs.

Blender Threejs
Blender Threejs

You need to install the Three.js Blender Export plugin from the Threejs GitHub repo: Copy the io_three directory to your Blender/2.7x/scripts/addons directory, and activate the plugin in the File -> User Preferences -> Add-ons Dialog (search for Three.js).

You should now be able to select Three (JSON) from the File -> Export dialog. Make sure to export it as Type: Geometry and include UVs:

Blender Threejs Export Dialog
Blender Threejs Export Dialog

Notice that we didn’t export any materials from Blender, because it’s easier to create the material in Threejs. Threejs creates a geometry out of the JSON file including its UV mapping, and a material out of the loaded image texture. Then we combine them into a mesh.

import * as THREE from 'three'

const createCastle = async scene => {
const loader = new THREE.JSONLoader()
const castleTexture = new THREE.TextureLoader().load(`/static/models/castle_texture.jpg`)
const castleMaterial = new THREE.MeshBasicMaterial({ map: castleTexture })
const castleGeometry = await new Promise(resolve => {
loader.load(`/static/models/castle.json`, geometry => {
const castle = new THREE.Mesh(castleGeometry, castleMaterial)

Adjust the scaling of your mesh to fit the scene.

// in createCastle
const scale = 0.1
castle.scale.set(scale, scale, scale)

You should now be able to see the rendered result in the browser:

Blender Threejs Browser
Blender Threejs Browser

Originally published at

Medium Clap
Medium Clap

Written by

Full Stack Software Engineer #javascript #EOS. Into Recreational Math / CS 🤯 Just message me about anything, my mind is open.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store