when i use aframe load .obj models ,there is an error occur, any .obj model can not load. who can help me,thanks !!

import 'aframe';
import 'aframe-animation-component';
import 'aframe-particle-system-component';
import 'babel-polyfill';
import {Entity, Scene} from 'aframe-react';
import React from 'react';
import ReactDOM from 'react-dom';
class AframeScene extends React.Component {
constructor(props) {
super(props);
this.state = {color: 'red'};
}
changeColor() {
const colors = ['red', 'orange', 'yellow', 'green', 'blue'];
this.setState({
color: colors[Math.floor(Math.random() * colors.length)]
});
}
render () {
return (
<Scene>
<a-assets>
<a-asset-item id="myModelObj" src="assets/models/test/box.obj"></a-asset-item>
<a-asset-item id="myModelMtl" src="assets/models/test/box.mtl"></a-asset-item>
</a-assets>
<a-entity obj-model="obj: #myModelObj; mtl: #myModelMtl" scale="1 1 1" position="-30 -15 -30" rotation="0 0 0"></a-entity>
</Scene>
);
}
}
export default AframeScene;
Look at the network tab in Developer Tools and see what response is coming for your OBJ file. This error probably means the OBJ or MTL file is not at the URL you've referenced.
There was a similar issue opened two days ago. @wlhm1984 are you working on the same project?
As commented in the other issue. Can you share your OBJ model? It seems your file is not well formed and you're getting a parsing error. I'm closing this since we keep Github issues for bugs and feature requests. For usage questions we rely on StackOverflow. You're also more than welcome to join the Slack channel and repost the question for more visibility.
I think the assets like .obj and .mtl are placed in ./src directory, which is unreachable as private. It works when they are moved to ./public directory.
I have the same issue, the .gtlf is this:
{
"asset": {
"version": "2.0",
"generator": "Open Asset Import Library (assimp v5.0.5eb040c7)"
},
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5126,
"count": 188,
"type": "VEC3",
"max": [
-577.6909790039063,
157.58229064941407,
-660.5927124023438
],
"min": [
-615.6214599609375,
-4.134796142578125,
-739.907470703125
]
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5125,
"count": 1026,
"type": "SCALAR",
"max": [
187
],
"min": [
0
]
}
],
"buffers": [
{
"byteLength": 6360,
"uri": "result.bin"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 2256,
"target": 34962
},
{
"buffer": 0,
"byteOffset": 2256,
"byteLength": 4104,
"target": 34963
}
],
"images": [
{
"uri": "Key_gold.png"
}
],
"materials": [
{
"name": "Key_silver",
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0
},
"baseColorFactor": [
0.800000011920929,
0.800000011920929,
0.800000011920929,
1.0
],
"metallicFactor": 0.0
}
}
],
"meshes": [
{
"name": "Key",
"primitives": [
{
"mode": 4,
"material": 0,
"indices": 1,
"attributes": {
"POSITION": 0
}
}
]
}
],
"nodes": [
{
"name": "RootNode",
"children": [
1
]
},
{
"name": "Key_$AssimpFbx$_Translation",
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
596.65625,
-76.62212371826172,
700.0,
1.0
],
"children": [
2
]
},
{
"name": "Key_$AssimpFbx$_RotationPivot",
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
-596.65625,
76.62212371826172,
-700.0,
1.0
],
"children": [
3
]
},
{
"name": "Key_$AssimpFbx$_RotationPivotInverse",
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
596.65625,
-76.62212371826172,
700.0,
1.0
],
"children": [
4
]
},
{
"name": "Key_$AssimpFbx$_ScalingPivot",
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
-596.65625,
76.62212371826172,
-700.0,
1.0
],
"children": [
5
]
},
{
"name": "Key_$AssimpFbx$_ScalingPivotInverse",
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
596.65625,
-76.62212371826172,
700.0,
1.0
],
"children": [
6
]
},
{
"name": "Key",
"mesh": 0
}
],
"samplers": [
{}
],
"scenes": [
{
"nodes": [
0
]
}
],
"textures": [
{
"source": 0,
"sampler": 0
}
],
"scene": 0
}
but I get the error when I try to load it like this:
<a-asset-item id="object" src="assets/treasure/key.gltf"></a-asset-item>
The material asset file is placed on the same directory as the .gltf file.
@netgfx this error usually means the model was not found, and the correct URL depends on the project structure. Check the Network tab in your developer tools to see where it is looking, and whether you can open that URL directly.
Most helpful comment
I think the assets like .obj and .mtl are placed in ./src directory, which is unreachable as private. It works when they are moved to ./public directory.