OBJ File for ARCore Application Development - augmented-reality

What is the significance of the andy.obj file in the ARCore Sample?
Let's say if we replace the andy.png with a new image, how can we generate .obj file for the new image?

The OBJ file describes the geometry, the png file the texture to "stretch" over this 3D object. You have to use a 3D modelling program like Blender to create a new model.
This is how you export OBJ files in Blender: https://blender.stackexchange.com/questions/121/how-do-i-export-a-model-to-obj-format

The sample code only can handle the simplest OBJ models that only have 1 texture file.
Fo those complicated OBJ models, they usually come with a MTL file that refers to several different texture files. To be able to handle that ,you need some extra work on the existing code. Please check the code I implement for this case if you are interested #https://github.com/JohnLXiang/arcore-sandbox . Specifially ,you can take a look at ObjectRenderer.createOnGlThread().

To export a texture as image in Blender do the following:
Select your object and enter in edit mode. Select all vertices/faces (press 'a'). Then start the UV Mapping, press 'u'. And Select one of the options of the UVMapping. You must test the best option for your model. I'm not sure which UV Mapping mapping option the ARCore uses.
Then go to the UV/Image Editor:
Export UV Layout at the menu, and save your image.

For creating a new .obj model for your AR app you need to use 3D authoring software like Autodesk Maya, Autodesk 3dsMax, Blender, SideFx Houdini, Cinema 4D, etc. These applications can help you create a high quality polygonal model with corresponding .mtl texture file.
But you should know that Sceneform supports 3D assets not only in OBJ format (where animations aren't supported) but also in FBX (with animations) and in glTF (animations not supported).
.obj
.fbx
.glTF
Sceneform's ASCII and Binary Asset Definitions are also welcome:
.sfa
.sfb
Supported material files (aka textures for your 3D assets) have the following extensions: MTL, BIN, PNG, JPG and native Sceneform's SFM.
.mtl
.bin
.png
.jpg
.sfm
Hope this helps.

Related

Importing .obj files with textures in SceneKit

I'm trying to render a 3D model .obj file downloaded from the web but I'm having issues with applying the textures to the model. .mlt, .obj and texture .jpg files are all in the same folder (e.g. car.obj, car.mtl, car.jpg, carDark.jpg).
Are the textures supposed to be applied automatically by Model I/O? How am I supposed to use Model I/O to import textures?
Did you check the file path to the .mtl file in the .obj file?
If this path is incorrect then the materials will not load.
OBJ and MTL files are text files so you can use a text editor to open them.
The path to the .mtl file should be at the top of the .obj file:
mtllib mymtlfile.mtl
If they are in the same folder you can just strip the path.
If this path is okay then you should check the paths to the textures in the .mtl file. Look for lines starting with map_. For instance:
map_Kd mydiffusetexture.png
map_Ka /path/to/myambienttexture.tga
map_bump mybumptexture.jpg
If you strip all the paths then the file import should work.
Add your textures images files in art.scnassets
Select your scene and select your textures in Material properties

How can i create materiallibrary and freeform in runtime in GLScene?

i want to write a ModelViewer to load many models in my Scene.
so how can i create GLMaterialLibrary in run time and assign it to FreeForms Objects in RunTime?
and i want to know how can i find the name of submodel's texture.
TanX for Help.
First of all, you do not need to create GlMaterialLibrary at run time as you can use single instance of GLMaterialLibriary for all scene GLFreeForms and dynamicaly link it to a new freeform. A TFreeForm or TActor can automatically setup the materials and load the textures from a 3DS files. You must first add a material library component to a form (which will store the materials, once the 3DS is loaded), then link the FreeForm to this material library and set
UseMeshMaterials := true;
After doing this, when loading the 3DS mesh, the importer will add new materials to the material library (using the names defined in the 3DS file), which you can later alter if you so wish.
Be aware that the image formats must be supported, for instance if your textures are JPeg files, you must add "JPeg" to your uses. And least but not last: GLScene comes with a very good pack of demos that you can check for refference. ..\Demos\materials\ folder contains everything what you need.

How to save a geometry and its material created in Three.js as collada file?

I'm relatively new to programming and currently trying to learn more about three.js, a JavaScript 3D library. Many things are relatively easy to understand, but I an having a hard time saving an geometry and its material.
I have build a simple cube and an image is projected on to it whenever a picture is loaded.
like this:
$('#picture')[0].onload = function() {
var texture = new THREE.Texture(this,null);
texture.needsUpdate = true;
cube.material = new THREE.MeshBasicMaterial( { map: texture } );
render();
}
My goal is to save the cube and its material. Ideally I would like to save it directly as a .dae file since another program in which i would like to import my cube only takes .dae files.
However, i can not find a collada exporter for THREE.js. Therefore, I searched for other exporters which can produce a file format I can open in e.g. Blender or MeshLab and save as .dae from there. Unfortunately, I have not been able to save both geometry and material/picture with these exporters:
GeometryExporter.js, OBJExporter.js, SceneExporter.js
I also looked into the combination of OBJ and MTL. I did find the OBJMTLLoader.js, however I lack the knowledge to rewrite the OBJMTLLoader.js in to a OBJMTLExporter.js
Can anyone help me find a way to get from a cube and its (picture) material in THREE.js to a .dae file?
For a very simple use case such as this, you could write the DAE manually, or even simpler, modify existing DAE on the fly. It's just XML if you change the file extension.
Create the simple cube with material in Blender, export it to DAE, and use it as a template. Simple DAE files are not very hard to read with text editor, you could find the relevant parts and just search & replace those parts in javascript (texture reference, material properties and UVs maybe).
This might not be exactly what you are looking for, but could work. Not many formats have proper support for materials, and I doubt you have much success finding a working, fully featured Three.js exporter for such a thing (not sure though).

How to make a change in Qualcomm's Vuforia Sample App

I have been looking through the threads at the Qualcomm Forums but no luck since I don't know exactly how to look for what I want.
I'm working with the ImageTargets Sample for iOS and I want to change the teapot to another image (a text rather) I had.
I already have the render and I got the .h using opengl library but I can't figure out what do I need to change to make this work and since this is the very basic and I haven't been able to make it work I really haven't ventured to try anything else.
Could anyone please help me out?
I would paste code here but it's a whole project so I don't know exactly what to put if needed please let me know.
If the case is still valid, here's what you have to do:
get header file for 3D object
get texture image for this object
in EAGLView.mm make this changes:
import "yourobject3d.h"
add your texture to textureFilenames array(this should be at the begining of EAGLView
eventually take care about kObjectScale (by deafult it was about 3.0f, for one object I did have to change it even up to 120.0f)
in setup3dObjects method assign proper arrays of vertices/normals/texture coords (check in "yourobject3d.h" file for proper arrays and naming) to Object3D *object
make this change in renderFrameQCAR
//glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices);
glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);
I believe that is all... if something take a look at Vuforia's forum, i.e. here: https://developer.vuforia.com/node/2047669
NOTE: default teapot.h does (!) have indices, which are not present in banana.h (from comment below) so take care about that too
Have a look at the EAGLView.mm file. There you'll have to load the textures (images) and 3d objects (you'll need to import your .h instead of teapot.h and modify setup3dObjects accordingly).
They are finally rendered by calling the renderFrameQCAR function.
Actually, teapot is not an image. It's a 3D model stored in .h format which includes Vertices, Normals, and Texture coordinates. You should have a good knowledge of OpenGL ES to understand those codes in sample app.
An easier way to change the 3D model to whatever you want is to use a rendering engine which facilitates the drawing and rendering stuffs and you don't need to bother OpenGL APIs. I've done it with jPCT-AE for Android platform but for iOS there is a counterpart called OpenFrameworks engine. It has some plugins to load 3Ds or MD2 files and since it's written in C++ you can easily integrate it with QCAR.
This is a short video of my result with jPCT and QCAR:
Qualcomm Vuforia + jPCT-AE test video

XNA File Load

In XNA, how do I load in a texture or mesh from a file without using the content pipeline?
The .FromFile method will not work on xbox or zune. You have two choices:
Just use the content pipeline ... on xbox or zune (if you care about them), you can't have user-supplied content anyways, so it doesn't matter if you only use the content pipeline.
Write code to load the texture (using .SetData), or of course to parse the model file and load the appropriate vertexbuffers, etc.
For anyone interested in loading a model from a file check out this tutorial:
http://creators.xna.com/en-us/sample/winforms_series2
This is a windows only Way to load a texture without loading it through the pipeline, As Cory stated above, all content must be compiled before loading it on the Xbox, and Zune.
Texture2D texture = Texture2D.FromFile(GraphicsDeviceManager.GraphicsDevice, #Location of your Texture Here.png);
I believe Texture2D.FromFile(); is what you are looking for.
It does not look like you can do this with a Model though.
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.texture2d.fromfile.aspx
If you really want to load an Xna Xna.Framework.Graphics.Model on PC without the content pipeline (eg for user generated content), there is a way. I used SlimDX to load an X file, and avoid the parsing code, the some reflection tricks to instantiate the Model (it is sealed and has a private constructor so wasn't meant to be extended or customised). See here: http://contenttracker.codeplex.com/SourceControl/changeset/view/20704#346981

Resources