viromedia / virocore

ViroCore cross-platform AR/VR renderer
MIT License
364 stars 108 forks source link

FBX to VRX converting and rendering issue #23

Closed jacobvyn closed 6 years ago

jacobvyn commented 6 years ago

Hi guys. I'm trying to convert FBX 3D model to VRX corresponds to your guide, described here https://virocore.viromedia.com/docs/3d-objects#section-fbx I have faced (probably)2 issues - first one while converting to vrx I see next Log:

➜  BB8 New 2 ./ViroFBX bb8.FBX bb8_v.vrx
2018-02-19 09:55:52.930 ViroFBX[14053:1134388] "Loading file [bb8.FBX]"
2018-02-19 09:55:52.938 ViroFBX[14053:1134388] "Import successful"
2018-02-19 09:55:53.000 ViroFBX[14053:1134388] "   Original up axis 2, sign 1"
2018-02-19 09:55:53.000 ViroFBX[14053:1134388] "   Original forward axis 2, sign 1"
2018-02-19 09:55:53.000 ViroFBX[14053:1134388] "   Coordinate system 0"
2018-02-19 09:55:53.000 ViroFBX[14053:1134388] "Triangulating scene..."
2018-02-19 09:55:53.001 ViroFBX[14053:1134388] "Exporting FBX..."
2018-02-19 09:55:53.004 ViroFBX[14053:1134388] "Exporting skeleton"
2018-02-19 09:55:53.005 ViroFBX[14053:1134388] "Exporting node [Object004], type [mesh]"
2018-02-19 09:55:53.005 ViroFBX[14053:1134388] "   Geo-only translation 0.447932, -0.201059, 52.013447"
2018-02-19 09:55:53.005 ViroFBX[14053:1134388] "   Geo-only rotation 0.000000, 0.000000, -35.500000"
2018-02-19 09:55:53.005 ViroFBX[14053:1134388] "   Exporting geometry"
2018-02-19 09:55:53.051 ViroFBX[14053:1134388] "      UV set name UVChannel_1"
2018-02-19 09:55:53.051 ViroFBX[14053:1134388] "      Polygon count 16290"
2018-02-19 09:55:53.093 ViroFBX[14053:1134388] "      Num vertices 48870, stride 48"
2018-02-19 09:55:53.093 ViroFBX[14053:1134388] "      VAR size 2345760"
2018-02-19 09:55:53.093 ViroFBX[14053:1134388] "   Exporting materials"
2018-02-19 09:55:53.093 ViroFBX[14053:1134388] "      Num materials 11"
2018-02-19 09:55:53.095 ViroFBX[14053:1134388] "      Primitive count for material 0: 2723"
2018-02-19 09:55:53.095 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.097 ViroFBX[14053:1134388] "      Primitive count for material 1: 228"
2018-02-19 09:55:53.097 ViroFBX[14053:1134388] "      Phong material"
2018-02-19 09:55:53.097 ViroFBX[14053:1134388] "         Opacity set to 1.000000"
2018-02-19 09:55:53.097 ViroFBX[14053:1134388] "      Primitive count for material 2: 228"
2018-02-19 09:55:53.097 ViroFBX[14053:1134388] "      Phong material"
2018-02-19 09:55:53.097 ViroFBX[14053:1134388] "         Opacity set to 1.000000"
2018-02-19 09:55:53.098 ViroFBX[14053:1134388] "      Primitive count for material 3: 832"
2018-02-19 09:55:53.098 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.098 ViroFBX[14053:1134388] "      Primitive count for material 4: 1280"
2018-02-19 09:55:53.098 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.099 ViroFBX[14053:1134388] "      Primitive count for material 5: 1920"
2018-02-19 09:55:53.099 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.100 ViroFBX[14053:1134388] "      Primitive count for material 6: 2050"
2018-02-19 09:55:53.100 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.101 ViroFBX[14053:1134388] "      Primitive count for material 7: 3600"
2018-02-19 09:55:53.101 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.102 ViroFBX[14053:1134388] "      Primitive count for material 8: 2149"
2018-02-19 09:55:53.102 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.102 ViroFBX[14053:1134388] "      Primitive count for material 9: 896"
2018-02-19 09:55:53.102 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.102 ViroFBX[14053:1134388] "      Primitive count for material 10: 384"
2018-02-19 09:55:53.103 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.106 ViroFBX[14053:1134388] "   No skeleton found, will not export skin"
2018-02-19 09:55:53.106 ViroFBX[14053:1134388] "   Exporting blend shape animations"
2018-02-19 09:55:53.106 ViroFBX[14053:1134388] "   Mesh had no deformers, not exporting blend shape animations"
2018-02-19 09:55:53.106 ViroFBX[14053:1134388] "   Exporting keyframe animations"
2018-02-19 09:55:53.106 ViroFBX[14053:1134388] "      Animation [Take 001] duration 3333 ms"
2018-02-19 09:55:53.107 ViroFBX[14053:1134388] "Exporting node [Box001], type [mesh]"
2018-02-19 09:55:53.107 ViroFBX[14053:1134388] "   Geo-only translation 39.511131, -27.978172, -44.302879"
2018-02-19 09:55:53.107 ViroFBX[14053:1134388] "   Geo-only rotation 29.701221, -38.995255, -77.494820"
2018-02-19 09:55:53.107 ViroFBX[14053:1134388] "   Exporting geometry"
2018-02-19 09:55:53.110 ViroFBX[14053:1134388] "      UV set name UVChannel_1"
2018-02-19 09:55:53.110 ViroFBX[14053:1134388] "      Polygon count 1200"
2018-02-19 09:55:53.112 ViroFBX[14053:1134388] "      Num vertices 3600, stride 48"
2018-02-19 09:55:53.112 ViroFBX[14053:1134388] "      VAR size 172800"
2018-02-19 09:55:53.113 ViroFBX[14053:1134388] "   Exporting materials"
2018-02-19 09:55:53.113 ViroFBX[14053:1134388] "      Num materials 1"
2018-02-19 09:55:53.113 ViroFBX[14053:1134388] "      Primitive count for material 0: 1200"
2018-02-19 09:55:53.113 ViroFBX[14053:1134388] "      WARNING: Unknown material type!"
2018-02-19 09:55:53.113 ViroFBX[14053:1134388] "   No skeleton found, will not export skin"
2018-02-19 09:55:53.113 ViroFBX[14053:1134388] "   Exporting blend shape animations"
2018-02-19 09:55:53.114 ViroFBX[14053:1134388] "   Mesh had no deformers, not exporting blend shape animations"
2018-02-19 09:55:53.114 ViroFBX[14053:1134388] "   Exporting keyframe animations"
2018-02-19 09:55:53.114 ViroFBX[14053:1134388] "      Animation [Take 001] duration 3333 ms"
2018-02-19 09:55:53.115 ViroFBX[14053:1134388] "Encoding protobuf [2739620 bytes]..."
2018-02-19 09:55:53.117 ViroFBX[14053:1134388] "Compressing..."
2018-02-19 09:55:53.286 ViroFBX[14053:1134388] "Writing protobuf [799705 bytes]"
2018-02-19 09:55:53.295 ViroFBX[14053:1134388] "Export complete"

Difference warnings look very suspiciously....

After that I have loaded vrx model as usual :

    Object3D model = new Object3D();
        model.setPosition(new Vector(0, 0, -2));
        model.setTag("bb8 model");
        model.loadModel(getUri("bb8_v.vrx"), Object3D.Type.FBX, new AsyncObject3DListener() {
            @Override
            public void onObject3DLoaded(Object3D object3D, Object3D.Type type) {
                Log.e(LOG_TAG, "loaded success tag " + object3D.getTag());
                Log.e(LOG_TAG, "geometry " + object3D.getGeometry());

                mArScene.getRootNode().addChildNode(object3D);
            }

            @Override
            public void onObject3DFailed(String s) {
                Log.e(LOG_TAG, s);
            }
        });

I got next log:

02-19 08:01:05.794 5927-6525 W/Viro: Copying asset at URL file:///android_asset/bb8_v.vrx

                                     [ 02-19 08:01:05.794   718: 6172 D/         ]
                                     Failed to fetch the lookup information of the device 0000000F 
02-19 08:01:05.810 5927-6525 I/Viro: Path to file is /data/user/0/com.example.virosample.arcore/cache/bb8_v.vrx
02-19 08:01:05.810 5927-6525 I/Viro: Loading FBX from file /data/user/0/com.example.virosample.arcore/cache/bb8_v.vrx
02-19 08:01:05.836 5927-6525 I/Viro: Read FBX protobuf
02-19 08:01:05.836 5927-6525 I/Viro: Loading node [Object004]
02-19 08:01:05.840 5927-6525 I/Viro:    Bounds x(-451.299805 451.299866)
02-19 08:01:05.841 5927-6525 I/Viro:           y(-451.299744 451.299927)
02-19 08:01:05.841 5927-6525 I/Viro:           z(-85.425293 921.074585)
02-19 08:01:05.841 5927-6525 I/Viro:    Added keyframe animation [Take 001]
02-19 08:01:05.841 5927-6525 I/Viro: Loading node [Box001]
02-19 08:01:05.841 5927-6525 I/Viro:    Bounds x(-50.000000 50.000000)
02-19 08:01:05.841 5927-6525 I/Viro:           y(-50.000000 50.000000)
02-19 08:01:05.841 5927-6525 I/Viro:           z(0.000000 100.000000)
02-19 08:01:05.841 5927-6525 I/Viro:    Added keyframe animation [Take 001]
02-19 08:01:05.848 5927-5927 E/ViroARActivity.Debug: loaded success tag bb8 model
02-19 08:01:05.848 5927-5927 E/ViroARActivity.Debug: geometry null

I have received message "load success" but 3d Objects geometry was always null, and of course nothing appears on the screen (AmbientLight is added). After that I have tried to do the same with 5 difference FBX models from difference sources - I had almost the same result... Link to described above asset https://free3d.com/3d-model/bb8-35865.html

UPDATED The best result I could get, was the white 3d model (without texture), and geometry was null as well. audi_r8 Asset for Audi R8 https://free3d.com/3d-model/audi-r8-14024.html converting log for Audi is warningless, so iI think the issue with BB8 is in fbx model itself. The question with white texture in vrx mode is open .

saboteur111 commented 6 years ago

Hi, jacobwyn- So I took a look at the R8 model and the BB8 model and this is what I found: R8 -This model is not made for real-time use. It's over 700k polys and for rendering only. This would not be efficient or work well on any platform. -There are no faces modeled in the undercarriage or interior of the car. That's why you're seeing null faces. -There are no textures assigned to the car. The ones that are included aren't being assigned and wouldn't be useful anyway. It seems the creator forgot to do this before making it public. -The reason why the car appears flat/white is you need to create scene lights. Ambient plus some directional light.

BB8 -The model does not have any of the included textures assigned to the model properly -I tried to manually assign the textures to the model but upon closer inspection of the UV's, it seems the creator uploaded some old version or a version that is not mapped to the textures correctly.

I suggest finding quality models on sites like turbosquid and following my guide here: https://blog.viromedia.com/https-blog-viromedia-com-asset-pipeline-optimizing-3d-models-ar-vr-arkit-arcore-d0fb61627aaf

geetves commented 6 years ago

I have the same problem also the default rotation is not proper.: screenshot_20180222-144629

The fbx file I used is this: https://www.turbosquid.com/3d-models/imola-bo-concept-3ds-free/572435

Can you please check and let me know what is the problem?

Thanks

saboteur111 commented 6 years ago

Hi, you actually successfully imported the model. I checked the chair and it does not have any textures assigned to it. If you notice, all the objects in your scene look flat. It is simply using colored shaders, so it is rendering correctly. You need to include some scene lights as well: https://docs.viromedia.com/docs/3d-scene-lighting. Try adding in some directional lights and you'll start to see some more value on the surfaces.

saboteur111 commented 6 years ago

Apologies, if using Virocore, reference this for lighting: https://virocore.viromedia.com/docs/3d-scene-lighting

geetves commented 6 years ago

Thanks for the response. I have few queries regarding this issue

  1. I am using this chair model in the sample project "ARPlacingObjects" provided by viromedia. In this project ambient light is already added to the scene.

`@Override public void onRendererStart() {

    mScene = new ARScene();
    //add a listener to the scene so we can update 'AR Init' text.
    mScene.setListener(new ARSceneListener(this, mViroView));
    //add a light to the scene so our models can show up.
    mScene.getRootNode().addLight(new AmbientLight(Color.WHITE, 1000f));
    mViroView.setScene(mScene);
    View.inflate(this, R.layout.viro_view_ar_hit_test_hud, ((ViewGroup) mViroView));
}`

Should I add some extra lights?

  1. When I open above chair model in Autodesk FBX Review, it is showing perfectly with shiny black texture. So Is this possible that texture is gone when I convert fbx to vrx? By the way I am newbie in graphics. So correct me if this is stupid question.

Thanks again.

jacobvyn commented 6 years ago

Hi @saboteur111, thanks for response. I have conducted an experiment, made simple model of 2 spheres in Blender, then converted to fbx and vrx, and after I have tried to render it I got only message that geometry is null...I am always facing this issue with very simple model... I suspect something is going wrong while converting to vrx... Spheres model is attached balls.fbx.zip

dam00n commented 6 years ago

@geetves yes, try adding a directional light also to your scene point down at the object -> https://virocore.viromedia.com/docs/3d-scene-lighting

If you are still having issues let us know

@jacobwyn thanks for the additional info. We will take a look at the models and see what the issue is.

saboteur111 commented 6 years ago

spheres.fbx.zip Hi @jacobwyn , I checked over the spheres in Maya and they seem fine other than they are very large in scale. It seems Blender has been causing issues w/ their FBX exporter. I re-exported them as fbx. Try converting them to vrx again and see if you get the same error.

dam00n commented 6 years ago

One more thing @jacobwyn, trying adding a directional light to your scene. Have the spheres positioned in front of you (you will need to scale them down a bit as mentioned above). Position the directional light at the camera origin [0,0,0] and set direction of the light pointing forward [0,0,-1]. This will illuminate the object from the view of the device.

img_0715

jacobvyn commented 6 years ago

Hi guys, thanks for the response. I have exported new spheres model to vrx and geometry is not null now but materials are null (didn't you delet it befor export to fbx?), but I do not see any sphere on the screen, I set scale, light and material

       AmbientLight ambientLight = new AmbientLight();
        ambientLight.setColor(Color.WHITE);
        ambientLight.setIntensity(1000);
        mArScene.getRootNode().addLight(ambientLight);

        Object3D model = new Object3D();
        Vector carPosition = new Vector(0, 0, -1);
        model.setPosition(carPosition);
        model.setScale(new Vector(5, 5, 5));
        model.loadModel(getUri("spheres_viro.vrx"), Object3D.Type.OBJ, new AsyncObject3DListener() {
            @Override
            public void onObject3DLoaded(final Object3D object3D, Object3D.Type type) {
                Log.e(LOG_TAG, "geometry " + object3D.getGeometry());

                Material material = new Material();
                Bitmap bitmap = Helper.getBitmapFromAsset(ViroARActivity.this, "steel.jpeg");
                Texture steelTexture = new Texture(bitmap, Texture.Format.RGBA8, true, true);
                material.setSpecularTexture(steelTexture);
                material.setDiffuseColor(Color.BLUE);
                material.setLightingModel(Material.LightingModel.PHYSICALLY_BASED);
                object3D.getGeometry().setMaterials(Arrays.asList(material));
                mArScene.getRootNode().addChildNode(object3D);
            }

            @Override
            public void onObject3DFailed(String s) {
                Log.e(LOG_TAG, s);
            }
        });

and have played with it in difference variations, I didn't manage to see spheres. By the way is it good practice to change material for VRX models?

I have check it with more advanced light with 3 sources of Spotlight and different colours - nothing.

There is the same issue with these simple model: https://www.turbosquid.com/3d-models/free-wine-glass-3d-model/768744 https://www.turbosquid.com/3d-models/free-legendary-soviet-table-glass-3d-model/825305 https://www.turbosquid.com/3d-models/scotch-glass-3ds-free/1125447

Maybe there is a new version of ViroFBX script? I got one from here https://virocore.viromedia.com/docs/3d-objects#section-fbx

Actually I am trying to check if Viro framework can render realistic textures such as steel and glass, so it should look like in real life with shyness and reflection or at least close to this. Is Viro able to do that?

Thanks a lot for you patience and help, in advance guys!

UPDATET From Log

Loading OBJ from file /data/user/0/com.example.virosample.arcore/cache/spheres_viro.vrx
02-26 10:47:21.102 26638-26961 I/Viro: OBJ # of vertices  = 0
02-26 10:47:21.102 26638-26961 I/Viro: OBJ # of normals   = 0
02-26 10:47:21.102 26638-26961 I/Viro: OBJ # of texcoords = 0
02-26 10:47:21.103 26638-26961 I/Viro: OBJ # of materials = 0
02-26 10:47:21.103 26638-26961 I/Viro: OBJ # of shapes    = 0
02-26 10:47:21.103 26638-26961 I/Viro: OBJ bounding box    =  x(340282346638528859811704183484516925440.000000 -340282346638528859811704183484516925440.000000) y(340282346638528859811704183484516925440.000000 -340282346638528859811704183484516925440.000000) z(340282346638528859811704183484516925440.000000 -340282346638528859811704183484516925440.000000)
dam00n commented 6 years ago

@jacobwyn did you try it with Directional lights at the position and direction we suggested? That should have worked as seen in the screen shot attached above.

If you are looking for realistic textures, you are probably talking about Physically Based Rendering (PBR). Yes, Viro does support that, but it is a different way of modeling and you can not just use simple models. Take a look at this blog post to understand how to create PBR models. There is also a sample model included -> https://blog.viromedia.com/asset-pipeline-exporting-pbr-textured-3d-models-for-ar-vr-arkit-arcore-c570423c68aa

jacobvyn commented 6 years ago

No, I didn't try to render it with Directional lights but I have tried with a few Spotlights from different sides and with different colours... judging by the description SpotLight is more flexible and more advanced Directional light....Thanks for link!

jacobvyn commented 6 years ago

Hello guys, I have few more questions: 1) I managed to render staff with PBR. In the sample, the reflection in 3d models are taken from image that I pass in Texture.loadRadianceHDRTexture(imageUri) but what if I want 3d model to reflect a world around? 2) I do not receive any callbacks while loading this model https://www.turbosquid.com/3d-models/3d-lamborghini-aventador-model/1117798 - try to load vrx - 3) In what case I'll need API to get the bounding box of any Node ? this API is declared in new ver 1.4.0 4) What does this line of log above mean? 02-26 10:47:21.103 26638-26961 I/Viro: OBJ bounding box = x(340282346638528859811704183484516925440.000000 -340282346638528859811704183484516925440.000000) y(340282346638528859811704183484516925440.000000 -340282346638528859811704183484516925440.000000) z(340282346638528859811704183484516925440.000000 -340282346638528859811704183484516925440.000000) 5) Is there an API that allows to get current frame from camera?

radvani commented 6 years ago

Hi @jacobwyn, in response to your questions:

  1. We don't have support for reflecting the world around you, yet, because we can only see what's through your back camera, which isn't enough to generate reflections. This is an active area of research, however.

  2. We will look into the issue regarding that model and get back to you shortly.

  3. The API to get a bounding box for a node just tells you how large your model is, in meters across the X, Y, and Z dimensions. Some customers wanted this information to help them place objects.

  4. That line of log is also the bounding box: it's in this following format: (minX, maxX), (minY, maxY), (minZ, maxZ). However, the bounding box in that log is before node transformations are applied; that is, it's the raw size of the OBJ right after loading. In your particular case the OBJ looks extremely large, perhaps malformed?

  5. We don't have this API yet. This should be coming in our next release.

radvani commented 6 years ago

Hi @jacobwyn, we've identified the problem with the Lamborghini model you were loading. It was using textures with spaces in their pathnames, which weren't being properly escaped. The issue has been fixed and you'll be able to use this model in our forthcoming release. Thanks.

jacobvyn commented 6 years ago

thanks!