UV mapping not working on imported obj file - libgdx

I have exported an .obj file (along with .mtl and a .png) from Blender to import into a libgdx project. The file contains both UV and normal data.
I am pulling the file into the app like this:
ModelLoader loader = new ObjLoader();
model = loader.loadModel(Gdx.files.internal("data/car.obj"));
The object should look like this: (Yes, I'm not an artist)
But it ends up looking like this:
What happened to my UV mapping?

Use loader.loadModel(Gdx.files.internal("data/car.obj"), true); to flip the vertical texture coordinates. You can also flip vertical textures coordinates while converting to the g3dx file format: fbx-conv -f car.obj (-f is for flip vertical texture coordinates), which will give you a file called car.g3db and is more suitable for rendering. More info on how to load and convert models (and flip texture coordinates) etc. can be found here: http://blog.xoppa.com/.

Just flip the texture vertically and load the texture it will work fine.
You can do it using photoshop.

Related

How to set a texture filter

How important is it to set a texture filter?
In the book Java Game Development with LibGDX in chapter 3 they set a texture filter.
When I load video assets with the assetmanager I can't convert a textureregion to a texture to set the texture filter.
But I can however set a texture filter on the entire spritesheet like so:
textureAtlas = assetManager.get("images/packed/game.pack.atlas") // all images are found in this global static variable
textureAtlas!!.findRegion("button").texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
How important is it to set a texture filter? Is this an ok solution? How can I get the textures from the atlas?
Textures always have a filter. If you don't set one, it will have the default filter of (Nearest, Nearest). This filter is appropriate for retro graphics (pixellated look). Otherwise, you'll most likely want to use (MipMapLinearLinear, Linear). If your game is mostly done and you've identified sprite drawing as a performance bottle-neck, then you can downgrade to (MipMapLinearNearest, Linear).
When creating an atlas using the TexturePacker, there is an option for texture filter, and if you set that you don't have to set it after you load the TextureAtlas in your game. You could also add a line at the top of your pack file like this:
filter: MipMapLinearLinear,Linear
Otherwise, if you want to set it on the atlas, it is fine with a single-page atlas to do what you did, and apply the filter using a texture reference from any of the texture regions, since they are all referencing the same Texture instance. But TextureAtlases can have multiple pages, so it would be more appropriate to do this:
for (Texture texture : textureAtlas.getTextures())
texture.setFilter(...);
Edit: To add settings to a TexturePacker build, put a text file named pack.json in the directory with the source images. You only have to add the settings that you want to change from the defaults. LibGDX can read simplified json that omits quotation marks for elements with no whitespace. So to just set the texture filter, this is all you need in the file:
{
filterMin: MipMapLinearLinear,
filterMag: Linear
}

threejs cannot parse material in json object

Dear all I am using angular 2.4.10 and three js 0.85.0. After downloading a JSON file from the server, I have at my disposal the following JSON object:
https://drive.google.com/file/d/0B7IcIHZN137RdmVRTXpLZmlPaDg/view?usp=sharing
I am trying to load the object without using the loader URL using the following code suggested in another StackOverflow post:
loadModel(aJSONObject) {
console.log(aJSONObject);
let loader = new THREE.ObjectLoader();
let model = loader.parse( aJSONObject );
console.log(model);
.....
}
and it's working but it is not getting the materials. How can I get the material from the JSON file?
I tried to load your model and the unique material got imported correctly.
However, there is no texture nor color defined for this material in the JSON model. So the object will look white, the default color used for three.js materials.
Fiddle here.
To see your model in three.js make sure to scale it appropriately based on you camera position (I had to scale it down).Moreover, as the model is using a THREE.MeshPhongMaterial, don't forget to add some lights.
By the way, there are some X, Y and Z individual attributes defined in your model that increase its size uselessly (three.js won't use them).

libgdx TextureAtlas, and NinePatch's

I am making a simple game using libgdx. I have a TextureAtlas that has I ninepatch I am trying to use:
The image is saved as menu.9.png
I am using the following code:
Image bg = new Image(Room.iAtlas.findRegion("GUI/menu"));
bg.setBounds(guix-border,guiy-border,(border+radius)*2,(border+radius)*2);
batch.begin();
bg.draw(s,1);
batch.end();
The output is like this:
I really just have no idea what I am doing wrong, but it should be more like this(Except it would have the shapes on top of it, but I didn't add those):
(I created that by hand, i've never actually had 9patch working, and it doesn't have the ships because I didn't bother to edit those in)
It looks like your "nine patch" isn't being treated as a real nine path, and is being treated as a "degenerate" nine patch (I had a very similar problem earlier: Loading nine-patch image as a Libgdx Scene2d Button background looks awful, though I wasn't using a TextureAtlas which is supposed to be the solution.)
Basically, when Libgdx reads the nine-patch out of your atlas, its supposed to read all the meta-data that describes how to chop the image up into 9 tiles (see https://code.google.com/p/libgdx/wiki/TexturePacker#NinePatches). I see a couple places this could go wrong:
Your texture isn't a valid nine-patch, and the meta-data is being ignored. (Check with the Android draw9patch tool.)
Your texture packer isn't processing the .9.png file correctly. Check the contents of the .txt file for your atlas, and see if it has "split" entries associated with the "menu.9.png" entry.
The texture lookup is just returning a regular TextureRegion wrapper for the nine-patch region, and isn't wrapping it in a NinePatch object. Try using TextureRegion.createNinePatch to make that more explicit. (I'm under the impression that this isn't necessary, but maybe it is ...)

actionscript-3 papervision3d mxmlc embedded collada model not showing

I am writing some code based on the following tutorial:
http://active.tutsplus.com/tutorials/3d/quick-tip-displaying-a-3d-model-with-papervision3d/
I copied the code from the example and added paths to my own assets.
[Embed(source="/Models/daeModel/cow.dae", mimeType="application/octet-stream")]
private var CowModelClass:Class;
[Embed(source="/Models/daeModel/Cow.png")]
private var CowTextureClass:Class;
[Embed(source="/Models/SkyDome/images.jpg")]
private var SkyTextureClass:Class;
[Embed(source="/Textures/grass-texture.jpg")]
private var GrassTextureClass:Class;
The assets shown above are used to display a Collada cow model standing on grass (plane) under a skydome (sphere), so my code differs slightly from the tutorial and I am loading Collada not DAE.
import org.papervision3d.objects.parsers.Collada;
I publish it in Flash CS3 and the .swf works perfectly. Cow model displays, grass plane and skydome all show up.
Unfortunately the assets are loaded at runtime because Flash CS3 does not embed.
To embed the assets I then compile the .as using mxmlc.exe using:
-static-link-runtime-shared-libraries=true
and I get no compilation errors.
However, when I run the .swf, the grass plane and the skydome appear normally with their embedded textures, but the collada model does not show.
My own debug text displays the width of the model as 0, so it looks like the model hasn't loaded. The Collada class still works fine because I am able to move the 3D co-ordinates of the model and thereby move some 3D text which is centred on the co-ordinates of the model. The text displays but the model is not visible.
By making a simple change I am able to check the model's texture 'Cow.png' by applying it to the grass plane, and it shows up fine. Because the texture is in the same folder as the model, I know that navigating the path to the model's location isn't the problem.
Does anyone know of any reason Collada models might not show after compile with mxmlc?
Am I missing any command line parameters or something obvious like that?
Failing that is there any other way of embedding this model?
Problem Solved!
Compiler mxmlc required me to define cowByteArray as XML:
//load cow model MXMLC
var cowByteArray:ByteArray = new CowModelClass ( );
cow = new Collada ( ) ;
cow.load ( new XML(cowByteArray), cowMaterialsList ) ;
Using the second code, after compiling with mxmlc, the model shows up fine!
Hope this helps somebody!

Away3d 4, creating a flat shaded material

I'm currently trying to create a "flat" shaded ColorMaterial inside of Away3d 4 to use as a mesh on a loaded .obj file.
This is a screenshot of what I'm trying to achieve. The flat shaded model is on the left.
I loaded the same .obj file I’m working with in Away into a program called MeshLab. MeshLab has two settings for Render Mode, flat or smooth.
The Flat render mode is on the left and smooth is on the right. When I load my .obj into Away3D the result looks exactly like MeshLab’s smooth render mode.
In order to get a flat result I’ve tried to set the smooth flag on my ColorMaterial to false but that doesn’t seem to change anything.
http://away3d.com/livedocs/away3d/4.0/away3d/materials/MaterialBase.html
I’m now starting to look into the materials shadowMethod because I was able to find a smooth boolean on ShadingMethodBase although I’m honestly not sure if this is where you would handle this.
http://away3d.com/livedocs/away3d/4.0/away3d/materials/DefaultMaterialBase.html#shadowMethod
http://away3d.com/livedocs/away3d/4.0/away3d/materials/methods/ShadingMethodBase.html
Below is the code for creating my light and light picker,
dL = new DirectionalLight();
dL.diffuse = 20;
dL.ambient=.6;
dL.specular=15
scene.addChild(dL);
lightPicker= new StaticLightPicker([dL]);
dL.direction = new Vector3D(0,1,-2);
And this is my material, I've tried playing around with most of it's properties:
primitiveMaterial = new ColorMaterial(0xcccccc);
primitiveMaterial.smooth = false;
primitiveMaterial.bothSides = false;
//primitiveMaterial.gloss = 800;
//primitiveMaterial.diffuseLightSources = LightSources.LIGHTS;
primitiveMaterial.diffuseMethod.alphaThreshold = .3;
primitiveMaterial.ambient =.2;
primitiveMaterial.lightPicker=lightPicker;
Can anyone help point me in the right direction?
Thanks!
ColorMaterial has no smooth attribute because it hasn't texture and smooth indicates whether or not any used textures should use smoothing. Most likely smooth attribute is inherited from MaterialBase and have no affect.
Your problem is in the normal vectors when surface is flat they are normals, when it is smoothed they are blended so it appears smoother.
Im guessing the problem might be in obj file. If it has no normals Away3d might generate them by it self ass well as MeshLab but Away3d apparently doing it only in smoothed mode by default. Or obj file contain smoothed normals and MeshLab overriding them in flat mode.
Open obj file with text editor and look for normals, try another obj file with flat surface.
But i might be wrong.
Here is smoothed obj
And this one is flat
What you are looking for is probably the Explode class.
Call Explode.apply(<your loaded mesh>) to remove the smoothed normals.