What does obj mean? How to open obj? What to do if the application from the list has already been installed

This tutorial shows how to load models from .obj files
The obj format is text files containing very little data about the model. But thanks to my
The simplicity of these files can be imported/exported by almost any relevant software.

The lesson code is taken from the "Loading Textures" lesson.
The disadvantage of the .obj format is that it does not store information about materials, so I had to come up with another way.
I wouldn't use this format for a demo or game, but it's useful to know how to handle it because
it is very simple and popular. In general, I should have written this lesson before loading the 3sd...

In this tutorial we will use STL vector. I described in detail what this is in the “loading.3ds” lesson.

Here's a short description of the OBJ format. Each program that exports and imports this format
does it his way. Some preserve normals, some preserve object names, and so on.

You read the data based on the first character in the line.

"v" - this line contains the vertex (x y z)

// example: v -1 -1 0

After reading all such lines, you will get the geometry of the object.

"vt" - texture coordinates of the object (U V)

// example: vt .99998 .99936

"f" - this line contains the vertex indices for the polygon array.
If there are UV coordinates, it also contains their indices.

// example: (vertices only): f 1 2 3

// example: (Vertices and textures): f 1/1 2/2 3/3

Now let's write a class that loads an .obj file.

New file: obj.h :

#ifndef _OBJ_H
#define_OBJ_H

#include "main.h"

// Class that loads an OBJ file
class CLoadObj(

public:

// You will only call this function. You just pass the structure
// models for saving data, and file name for loading.
bool ImportObj(t3DModel * pModel, char * strFileName) ;

// Main loading loop called from ImportObj()
void ReadObjFile(t3DModel * pModel) ;

// Called in ReadObjFile() if the line starts with "v"
void ReadVertexInfo() ;

// Called in ReadObjFile() if the line starts with "f"
void ReadFaceInfo() ;

// Called after loading polygon information
void FillInObjectInfo(t3DModel * pModel) ;

// Calculate normals. This is not required, but highly recommended.
void ComputeNormals(t3DModel * pModel) ;

// Since .obj files do not store texture names and material information, we will create
// a function that sets them manually. materialID - index for the pMaterial array of our model.
void SetObjectMaterial(t3DModel * pModel, int whichObject, int materialID) ;

// To make it easier to assign material to an .obj object, let's create a function for this.
// Pass the model, material name, texture file name and RGB color into it.
// If we only need the color, pass NULL to strFile.
void AddMaterial(t3DModel * pModel, char * strName, char * strFile,
int r = 255, int g = 255, int b = 255);

private:

// Pointer to file
FILE * m_FilePointer;

// STL vector containing a list of vertices
vector< CVector3>m_pVertices;

// STL vector containing a list of polygons
vector< tFace>m_pFaces;

// STL vector containing a list of UV coordinates
vector< CVector2>m_pTextureCoords;

// Tells us if the object has texture coordinates
bool m_bObjectHasUV;

// Tells us we just read polygon data so we can read multiple objects
bool m_bJustReadAFace;
} ;

#endif

obj.cpp file:
#include "main.h"
#include "obj.h"


///// The function loads the .obj file into the specified variable from the specified file name
//////////////////////////////// IMPORT OBJ \\\\\\\\\\\\\\\\ \*

Bool CLoadObj::ImportObj(t3DModel *pModel, char *strFileName)
{
char strMessage = (0); // Will be used to report an error

// Make sure that the model and file name are not empty
if(!pModel || !strFileName) return false;

// Open the specified file for reading
m_FilePointer = fopen(strFileName, "r");

// Make sure the file is opened correctly
if(!m_FilePointer) (
// Generate an error message
sprintf(strMessage, "Unable to find or open the file: %s", strFileName);
MessageBox(NULL, strMessage, "Error", MB_OK);
return false;
}

// Now, having open file, read the information
ReadObjFile(pModel);

// After reading all the information, calculate the vertex normals
ComputeNormals(pModel);

// Close the file
fclose(m_FilePointer);

// And return true
return true;
}


///// This function is the main loop for reading the file.obj
//////////////////////////////// READ OBJ FILE \\\\\\\\\\\\\\\ \\*

Void CLoadObj::ReadObjFile(t3DModel *pModel)
{
char strLine = (0);
char ch = 0;

While(!feof(m_FilePointer))
{
float x = 0.0f, y = 0.0f, z = 0.0f;

// Read the first character of the current line of the file
ch = fgetc(m_FilePointer);

Switch(ch)
{
case "v": // Check if this is not "v" (could be a vertex/normal/text coordinate)

// If we were just reading information about the polygon, and now we are reading the vertex,
// this means we have moved on to the next object, and we need to save the data from the previous one.
if(m_bJustReadAFace) (
// Save the data of the last object into the model structure
FillInObjectInfo(pModel);
}

// Decrypt the entire current line
ReadVertexInfo();
break;

Case "f": // If the first character is "f", this line describes the polygon

// If the newline character read is an empty string, do nothing.
break;

Default:
// If something is unknown, just read this line into "garbage" to go
// to the next one - we don't need it.

break;
}
}

// Now save the last read object
FillInObjectInfo(pModel);
}


///// This function reads information about vertices ("v" vertex: "vt" UVCoord)
//////////////////////////////// READ VERTEX INFO \\\\\\\\\\\\\\\ \\*

Void CLoadObj::ReadVertexInfo()
{
CVector3 vNewVertex = (0);
CVector2 vNewTexCoord = (0);
char strLine = (0);
char ch = 0;

// Read the second character of the line to see what the line contains: vertices/normals/UV
ch = fgetc(m_FilePointer);

// Read the rest of the line to move on to the next one
fgets(strLine, 100, m_FilePointer);

// Add a new vertex to the list
m_pVertices.push_back(vNewVertex);
}
else if(ch == "t") // If the second character is "t", the string contains the UV coordinates ("vt")
{
// Read texture coordinates. Format: "vt u v"
fscanf(m_FilePointer, "%f %f", &vNewTexCoord.x, &vNewTexCoord.y);

// Read the remaining line to move on to the next one
fgets(strLine, 100, m_FilePointer);

// Add new texture coordinates to the list
m_pTextureCoords.push_back(vNewTexCoord);

// Activate the flag indicating that the object has texture coordinates.
// Now we know that polygon strings will contain indices not only
// vertices, but also text. coordinates ("f 1/1 2/2 3/3")
m_bObjectHasUV = true;
}
else // Otherwise, this is apparently a normal, and we don’t need it (“vn”)
{
// We're calculating our own normals, so we'll skip the line
fgets(strLine, 100, m_FilePointer);
}
}


///// Reads polygon information ("f")
//////////////////////////////// READ FACE INFO \\\\\\\\\\\\\\\ \\*

Void CLoadObj::ReadFaceInfo()
{
tFace newFace = (0);
char strLine = (0);

// The function reads information about the object's polygons.
// This information is the 3D points that make up the polygon and the UV coordinates,
// if a texture is applied to the object.
// If the object has texture coordinates, the string format will be
// like this: "f v1/uv1 v2/uv2 v3/uv3"
// Otherwise like this: "f v1 v2 v3"
// Attention! Always make sure to subtract 1 from the indices since
// arrays in c++ start from 0, and indexes in .obj start from 1.

// Check if the object has texture coordinates
if(m_bObjectHasUV)
{
// Read the indices of vertices and texture coordinates.
fscanf(m_FilePointer, "%d/%d %d/%d %d/%d", &newFace.vertIndex, &newFace.coordIndex,
&newFace.vertIndex, &newFace.coordIndex,
&newFace.vertIndex, &newFace.coordIndex);
}
else // if the object does NOT contain texture coordinates
{
// Read only vertex indices
fscanf(m_FilePointer, "%d %d %d", &newFace.vertIndex,
&newFace.vertIndex,
&newFace.vertIndex);
}

// Read the line to the end to move on to the next one
fgets(strLine, 100, m_FilePointer);

// Add a new polygon to the list
m_pFaces.push_back(newFace);

// Set this flag to TRUE to know we just read a polygon. If
// after this the vertex is read - which means we have moved on to the next object and we need
// save this one.
m_bJustReadAFace = true;

Are you having trouble opening .OBJ files? We collect information about file formats and we can tell you what OBJ files are needed for. Additionally, we recommend programs that are most suitable for opening or converting such files.

What is the .OBJ file format used for?

File extension .obj primarily denotes the Wavefront 3D Model file format ( .obj), developed by Wavefront Technologies for its Advanced Visualizer visualization program. OBJ is a text format for describing the geometry of three-dimensional bodies, allowing you to model complex volumetric shapes and apply them to various materials and textures.

File .obj is the main component of the Wavefront 3D model. It is this large text document that defines the entire geometry of the model. Besides the file .obj, a typical Wavefront 3D object or scene typically also includes one or more Material Template Library (.mtl) files that define the object's materials with references to external raster textures, usually stored in a separate subdirectory ( e.g. "Textures").



OBJ has become one of the most popular and supported 3D model formats, and file export/import functions .obj present in almost every 3D editor. Open files .obj Many utilities for viewing 3D models are capable of displaying the contained models with full rendering, and a number of converters allow you to convert OBJ models to other formats. There are entire collections and libraries of models in this format on the Internet.

In addition, the extension .obj serves as a designation for the Compiled Object Code file type ( .obj) in relation to several object file formats used on the Microsoft Windows platform. Object file ( .obj) is created by compiling source code and contains platform- and architecture-specific machine code, as well as linkage data, symbolic cross-references, and other data. Unlike compiled executable files (.exe), object files ( .obj) cannot be sent directly for execution; rather, they act as application libraries. Previously expansion .obj was used exclusively to refer to the Relocatable Object Module Format (OMF) in MS-DOS and 16-bit editions of Windows.

Programs for opening or converting OBJ files

You can open OBJ files with the following programs: 

Files with the .obj extension contain files of 3D objects created using a computer drawing program. Such files may contain texture maps, 3D coordinates, and other information about 3D objects.

The OBJ format is used in a wide variety of 3D graphics applications, including Microsoft Visual Studio and CADRazor.

In addition, the suffix.obj is used when working with computer science object files. Such files contain a set of sequences - instructions that allow the host computer to correctly perform assigned tasks. In this case, OBJ files may be accompanied by corresponding metadata files.

OBJ files are also produced by several compilers for Windows, for example. C and C++. As a result of processing the file's source code, a file with the .obj extension appears. Once all the source code files are compiled into OBJ files, they are linked together to form an EXE or DLL file.

In IT areas related to 3D graphics, you can often find models in the OBJ format. The file format in question is text file, containing only the geometry of 3D objects, i.e. stores vertex positions, vertex normals, and texture coordinates. Material information is stored in an MTL file, which is referenced at the beginning of the file using the mtllib directive.

The OBJ 3D graphics description format is very popular because it is simple to describe and is supported by almost all 3D editors. Before considering which programs open OBJ, it should be noted that sometimes the purpose of opening a file is not to view the model, but, for example, to get acquainted with a list of object names, or to count the number of vertices. These and other steps can be performed by opening the file in a regular text editor, such as Notepad++.

So, let's look at how to open files with the OBJ extension? Here are the most popular programs with which you can easily view a 3D model.

How to open OBJ in Blender?

To open an OBJ file in Blender, in the main menu, select “File” - “Import” - “Wavefont (.obj)” in the main menu. In the dialog box that opens, you will need to specify the OBJ file and click the “Import OBJ” button.

Attention! In order for textures to be displayed in addition to polygons, it is necessary that the paths to the MTL file be correctly specified in the OBJ file, and the paths to the pictures must be correctly specified in the MTL file.

How to open OBJ in 3D Max?

Another very popular 3D modeling program is Autodesk 3ds Max. It should also use the function of importing third-party files: “Import” - “Import non-native file formats into 3ds Max”.

How to open OBJ in Sketchup?

SketchUp is available as both a desktop application and an online editor. Registration required for online version account. Like any other 3D editor, Sketchup supports importing many formats, including the OBJ extension. To import, use the “OBJ Importer” plugin located in the “Plugins” tab. There are two import options available in the drop-down submenu - as OBJ and as Mesh.

How to open OBJ format in Archicad?

There is no way to directly open an OBJ file in Archicad. To view the model in Archicad you will need:

1. Convert OBJ format file to 3DS. To do this, you can use the programs 3DS Max, Cinema 4K, etc.
2. Import 3DS using standard means: “Interaction” - “3D Studio” - “Import 3DS as a GDL object...”.

How to open OBJ in MeshLab?

In order to load an OBJ format model in the MeshLab program, go to the top menu and select “File” - “Import Mesh...”. After selecting the desired file, the 3D model will open in the central window of the application. For ease of viewing, you can use the buttons to enable/disable the display of vertices, boundaries and polygons.

How to open OBJ online?

If you don’t have any of the listed programs on your computer, and you don’t have time to download them, you can use an online viewer for files with the OBJ extension. To do this, just enter the phrase “obj open online” into a search engine. As such an online editor, you can use https://threejs.org/editor/ - written on the Three.js engine, which allows you to work with 3D graphics using WebGL.

Most common cause The problem with opening the OBJ file is simply the lack of appropriate applications installed on your computer. In this case, it is enough to find, download and install an application that serves files in the OBJ format - such programs are available below.

Search system

Enter file extension

Help

Clue

Please note that some encoded data from files that our computer does not read can sometimes be viewed in Notepad. In this way we will read fragments of text or numbers - It is worth checking whether this method also works in the case of OBJ files.

What to do if the application from the list has already been installed?

Often an installed application should automatically link to the OBJ file. If this does not happen, then the OBJ file can be successfully linked manually with the newly installed application. Simply right-click on the OBJ file, and then from the available list select the "Choose default program" option. Then you need to select the “View” option and find your favorite application. The entered changes must be approved using the "OK" option.

Programs that open the OBJ file

Windows
Mac OS
Linux

Why can't I open the OBJ file?

Problems with OBJ files can also have other causes. Sometimes even installing software on your computer that supports OBJ files will not solve the problem. The reason for the inability to open and work with the OBJ file may also be:

Inappropriate OBJ file associations in registry entries
- corruption of the OBJ file we open
- OBJ file infection (viruses)
- too little computer resource
- outdated drivers
- removal of the OBJ extension from the Windows registry
- incomplete installation of a program that supports the OBJ extension

Fixing these issues should result in freely opening and working with OBJ files. In case your computer still has problems with files, you need to take the help of an expert who will determine the exact cause.

My computer does not show file extensions, what should I do?

In standard Windows system settings, the computer user does not see the OBJ file extension. This can be successfully changed in the settings. Just go to the "Control Panel" and select "View and Personalization". Then you need to go to "Folder Options" and open "View". In the "View" tab there is an option "Hide extensions of known file types" - you must select this option and confirm the operation by clicking the "OK" button. At this point, the extensions of all files, including OBJ, should appear sorted by file name.

Did you like the article? Share with friends: