Jump to content
  • entries
    338
  • comments
    905
  • views
    259,835

Unity - handrolling meshes


EricBall

1,289 views

The other day I decided I needed to set myself a goal to work on in Unity. A game project to help focus my self education.

 

What I settled on is a Battlezone style game. (Not a port - just the basic ideas.)

 

So one of the things I need is a tank to shoot at. Which means I need to create a model which Unity will then display. While I could download Blender (also free), that seems like overkill for something as simple as a Battlezone tank. What I wanted was something dead simple - an ASCII file format which Unity could use to create simple objects.

 

With some Googling I learned the "OBJ file" supported by Unity was just that - a simple ASCII file format. So I sketched out my tank (which is even simpler than the supertank in Battlezone), figured out the coordinates for the vertices and mapped those to faces. All nice & neat - and I even commented stuff.

 

And Unity refused to load it.

 

At first I didn't even see the error message - putting it in the scene just created an empty object. But then I happened to look at the console and saw the ImportFBX error (which confused me even more as FBX is a completely different file format).

 

I bashed my head against the keyboard trying to figure out what I was doing wrong. Was it because my OBJ file was too simple? (I didn't specify normals or a texture.) I selected different options to no avail. Was I missing something in the file which was causing Unity to misidentify it? I copied the sample file I used as a template and it failed too.

 

Then I grabbed another OBJ file off the web and that one worked. Huh? I looked at the file closely. It didn't include normals or textures either. The basic format was the same. Then I saw it - this file didn't have comments after the vertices and faces. So I removed them from mine and Unity was happy - and so was I.

 

 

5 Comments


Recommended Comments

I wrote an OBJ converter back in 2010 to import models into our spacecraft design suite. You can see the results of importing a shuttle model on our homepage. The software originally ran under X11, I was hired on to do the Windows port. Nathan did some freelance work us, he did the button and icon graphics for the port.

 

Might you have used the wrong notation for comments in the OBJ file? I just checked the shuttle OBJ and MTL files I used to test my routines and all the comments start with #. That follows what I see at wikipedia.

Link to comment

Hi Darrell,

 

Here's the sample I used (which fails):

 

# WaveFront .obj file - a single square based pyramid

# Start a new group:

g SquareBasedPyramid

# List of vertices:

v -0.5 0 0.5 # Front left.

v 0.5 0 0.5 # Front right.

v 0.5 0 -0.5 # Back right

v -0.5 0 -0.5 # Back left.

v 0 1 0 # Top point (top of pyramid).

# List of faces:

f 4 3 2 1 # Square base (note: normals are placed anti-clockwise).

f 1 2 5 # Triangle on front.

f 3 4 5 # Triangle on back.

f 4 1 5 # Triangle on left side.

f 2 3 5 # Triangle on right side.

Unity doesn't handle the in-line comments like # Front left. Remove them and it works fine.
Link to comment

I used google sketchup to make simple shapes like mazes and imported to unity a few years ago(maybe it was blender?) However, they sold it to Trimble a while back and I don't know what kind of files the free version will output.

Link to comment

I didn't notice that, though it does match what Wiki has about the OBJ file:

Lines beginning with a hash character (#) are comments.


Just booted up the work machine and all the comments are on lines by themselves.

Wiki does show inline comments in the MTL file, though the files I have are on lines by themselves like in the OBJ files.

Link to comment

Unfortunately, the SketchUp Make license is for non-commercial use only. (Not that I have any plans to make money, but Blender doesn't have that restriction.)

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...