Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I load a 3d model in Aframejs? It currently works fine in threejs

I have created a 3d animated model, which I managed to run in threejs.

var loader = new THREE.FBXLoader();
loader.load( 'model.fbx', function ( object ) {              
     object.mixer = new THREE.AnimationMixer( object );
     mixers.push( object.mixer );
     console.log(object.animations.length);
     var action = object.mixer.clipAction( object.animations[ 0 ] );
     action.play();
     object.traverse( function ( child ) { 
       if ( child.isMesh ) { 
          child.castShadow = true;
          child.receiveShadow = true; 
       } 
     });
     scene.add( object );
});

It works perfectly fine on threejs, but how can I use it in aframe, I am trying to create AR app. I am not getting enough documentation, in AFrame I can display obj model on marker but aframe-extras doesn't seem to work, but Threejs FBX loader works fine. I need help to display threejs scene on on marker scan.

like image 488
Omkar Frozen Avatar asked Mar 06 '18 17:03

Omkar Frozen


People also ask

Does Sketchfab use 3 JS?

js App. Sketchfab's API gives you programmatic access to the largest collection of glTF 3D models on the web.

What file types does three Js support?

The three. js library offers loaders for numerous file formats like FBX, Collada as well as OBJ but the recommended format for importing and exporting data is glTF. The great thing about glTF file format is that it is very compact and can be easily transmitted and also loading very fast.

What is three Js used for?

three. js is a JavaScript-based WebGL engine that can run GPU-powered games and other graphics-powered apps straight from the browser. The three. js library provides many features and APIs for drawing 3D scenes in your browser.


2 Answers

I used FBX2glTF to convert model to glTF and worked fine for me. https://github.com/facebookincubator/FBX2glTF

like image 117
ngokevin Avatar answered Sep 18 '22 18:09

ngokevin


Regarding the topic: 3D models in a-frame

Try using the three.js JSON, or glTF formats. Both formats are recommended by the a-frame team in the docs.

I remember Don McCurdy pointing out that the fbx models are complicated and hard to interpret, that's why JSON formats came to webGL.

While working with ar.js i remember having no problems using Three.js JSON models with multiple animations, as well as glTF static/one-animation models.

You can easily export you model to gltf using khronos, or kupomans exporters, and three.js JSON using this one.

Furthermore, the glTF models work with the core a-frame library, without any additions !


Regarding fbx's, i've never got them to work properly, so since the other ones are designed for webGL i'd try them out.

like image 33
Piotr Adam Milewski Avatar answered Sep 18 '22 18:09

Piotr Adam Milewski