question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mtl file not loading

See original GitHub issue

I’m trying to load an obj with an mtl, but for some reason the mtl is never applied.

code ->


import Expo from 'expo';
import React from 'react';

import * as THREE from 'three'; 

import ExpoTHREE from 'expo-three';

console.disableYellowBox = true;

export default class App extends React.Component {
  render() {
    return (
      <Expo.GLView
        ref={(ref) => this._glView = ref}
        style={{ flex: 1 }}
        onContextCreate={this._onGLContextCreate}
      />
    );
  }

  _onGLContextCreate = async (gl) => {
    const width = gl.drawingBufferWidth;
    const height = gl.drawingBufferHeight;

    const arSession = await this._glView.startARSessionAsync();

    const scene = new THREE.Scene();
    const camera = ExpoTHREE.createARCamera(arSession, width, height, 0.01, 1000);
    const renderer = ExpoTHREE.createRenderer({ gl });
    renderer.setSize(gl.drawingBufferWidth, gl.drawingBufferHeight);

    scene.background = ExpoTHREE.createARBackgroundTexture(arSession, renderer);

    const ambientLight = new THREE.AmbientLight(0xaaaaaa);
    scene.add(ambientLight);

    // //model files
    const model = {
      'artest.obj': require('./models/artest.obj'),
      'artest.mtl': require('./models/artest.mtl'),
    };

    /// Load model
    const mesh = await ExpoTHREE.loadAsync(
      [model['artest.obj'], model['artest.mtl']],
      null,
      name => model[name],
    );

    /// Update size and position
    ExpoTHREE.utils.scaleLongestSideToSize(mesh, 5);
    ExpoTHREE.utils.alignMesh(mesh, { y: 1 });

    mesh.scale.set(0.00001, 0.00001, 0.00001);

    /// Add the mesh to the scene
    scene.add(mesh);

    const animate = () => {
      requestAnimationFrame(animate);
      renderer.render(scene, camera);
      gl.endFrameEXP();
    }
    animate();
  }
}

If you would have any input as to what I might be doing wrong, would be great.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
EvanBaconcommented, Jun 14, 2018

ExpoTHREE.loadMtlAsync should fix this

0reactions
shuyaoyimeicommented, Nov 17, 2019

Did you add “mtl” to your app.json

how to add “mtl” to app.json, like this ?

"packagerOpts": {
      "assetExts": [
        "dae",
        "obj",
        "mtl",
        "amf",
        "3mf",
        "3ds",
        "jpg",
        "assimp",
        "fbx",
        "pmd",
        "vmd",
        "ply",
        "stl",
        "vtk",
        "vtp",
        "babylon",
        "drc",
        "pcd",
        "pack",
        "bvh",
        "x"
      ]
    },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing OBJ with MTL and Image not working properly
1. Check the obj file. In your case the obj is not exported correctly. Obj is a human readable file format it is...
Read more >
The .mtl files won't load - Materials and Textures - Blender Artists
Open the mtl file in a text editor and check any file paths to textures are correct. Furlow (Furlow) November 30, 2012, ...
Read more >
Importing OBJ file does not bring in mtl so model is grey
Solved: When I import obj file into maya, the model imports but all the color has gone and I am left with a...
Read more >
html - .mtl file not rendering properly - Stack Overflow
I have .obj file and .mtl file and I'm trying to render those file using THREE.JS. But obj was loaded but colors and...
Read more >
Problems loading MTL · Issue #1167 · potree/potree - GitHub
When including the mtl-files I get an error pointing to a "file not found" I can fix this by editing the MTLLoader.js file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found