Example #1
0
static void LoadEditChunk( FILE *fp, long thisChunkLen, _3DSEditChunk_t *pEC ){
	unsigned short chunkID;
	long chunkLen;
	long bytesRead = 0;
	_3DSEditChunk_t editChunk;

	_3DSMaterial_t mat[MAX_MATERIALS];
	_3DSNamedObject_t namedObjects[MAX_NAMED_OBJECTS];

	int numMaterials = 0, numNamedObjects = 0;

	memset( &editChunk, 0, sizeof( editChunk ) );

	if ( s_verbose ) {
		printf( ">>> EDIT CHUNK\n" );
	}

	while ( ReadChunkAndLength( fp, &chunkID, &chunkLen ) )
	{
		switch ( chunkID )
		{
		case _3DS_CHUNK_MAT_LIST:
			LoadMaterialList( fp, chunkLen - 6, &mat[numMaterials] );
			numMaterials++;
			break;
		case _3DS_CHUNK_NAMED_OBJECT:
			LoadNamedObject( fp, chunkLen - 6, &namedObjects[numNamedObjects] );
			if ( namedObjects[numNamedObjects].numTriObjects != 0 ) {
				++numNamedObjects;
			}
			break;
		case _3DS_CHUNK_MESH_VERSION:
		default:
			fread( s_buffer, chunkLen - 6, 1, fp );
			break;
		}

		bytesRead += chunkLen;

		if ( bytesRead >= thisChunkLen ) {
			break;
		}
	}

	if ( numMaterials == 0 ) {
		numMaterials = 1;
		strcpy( mat[0].name, "(null)" );
		printf( "Warning: no material definitions found\n" );
	}

	pEC->numNamedObjects = numNamedObjects;

	pEC->pMaterials = malloc( sizeof( _3DSMaterial_t ) * numMaterials );
	pEC->pNamedObjects = malloc( sizeof( _3DSNamedObject_t ) * numNamedObjects );

	memcpy( pEC->pMaterials, mat, numMaterials * sizeof( mat[0] ) );
	memcpy( pEC->pNamedObjects, namedObjects, numNamedObjects * sizeof( namedObjects[0] ) );
}
Example #2
0
extern "C" void _VenomModuleLoad(GameMemory *memory) {
#ifdef VENOM_HOTLOAD
#define _(returnType, name, ...) name = memory->engineAPI.name;
EngineAPIList
#undef _
#define _(signature, name) name = memory->engineAPI.name;
#include "opengl_procedures.h"
#undef _ 
#endif//VENOM_HOTLOAD
	
	ImGuiIO& io = ImGui::GetIO();
  
	SystemInfo *system = &memory->systemInfo;
  io.KeyMap[ImGuiKey_Enter] = KEYCODE_ENTER;
	io.KeyMap[ImGuiKey_Escape] = KEYCODE_ESCAPE;
	io.KeyMap[ImGuiKey_Tab] = KEYCODE_TAB;
	io.KeyMap[ImGuiKey_Backspace] = KEYCODE_BACKSPACE;
	io.KeyMap[ImGuiKey_LeftArrow] = KEYCODE_LEFT;
	io.KeyMap[ImGuiKey_RightArrow] = KEYCODE_RIGHT;
	io.KeyMap[ImGuiKey_DownArrow] = KEYCODE_DOWN;
	io.KeyMap[ImGuiKey_UpArrow] = KEYCODE_UP;

  io.KeyMap[ImGuiKey_A] = KEYCODE_A;
  io.KeyMap[ImGuiKey_C] = KEYCODE_C;
  io.KeyMap[ImGuiKey_V] = KEYCODE_V;
  io.KeyMap[ImGuiKey_X] = KEYCODE_X;
  io.KeyMap[ImGuiKey_Y] = KEYCODE_Y; 
  io.KeyMap[ImGuiKey_Z] = KEYCODE_Z; 
  memory->keyEventCallback = HackVenomKeyEventCallback;

	io.RenderDrawListsFn = RenderImGuiDrawList;
	io.DisplaySize = ImVec2(system->screenWidth, system->screenHeight);
	io.UserData = memory;

  U8* pixels;
  int width, height, components;
  //io.Fonts->AddFontFromFileTTF("/usr/share/fonts/TTF/DejaVuSans.ttf", 14);
  io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &components);
	io.Fonts->TexID = (void *)(size_t)memory->renderState.imguiFontTexture;

#if 0
  { //Reload the MaterialList Why the hell are we doing this?
    MaterialAssetList* list = &memory->assets.materialAssetList;
    LoadMaterialList(list);
  }
#endif

  InitalizeEditor(&memory->editor);
  VenomModuleLoad(memory);
}
Example #3
0
int PI3DParseFile(PI3DImport *importer)
{
	bool			readFaces = true;
	char			*line = new char[MAX_LINE];
	char			*token = new char[MAX_LINE];
	char			*str = new char[MAX_LINE];
	char			*currentMaterial = new char[MAX_LINE];
	PI3DMesh			*mesh;
	PI3DMaterial		*material;
	int32			currentMaterialID;
	int32			maxVertices = 8;
	int32			maxNormals = 8;
	int32			maxUVs = 8;
	int32			maxFaces = 8;

	// initialize the scene
	strncpy(currentMaterial, "__PS_CS3_3D_Default", MAX_LINE-1);
	currentMaterial[MAX_LINE-1] = '\0';
	currentMaterialID = 0;
	material = PI3DUpdateMaterials(importer->scene, currentMaterial, 0);
	material->diffuse.red = 1.0;
	material->diffuse.green = 1.0;
	material->diffuse.blue = 1.0;

	mesh = PI3DCreateMesh((char*)"", 0, 0, 0, 0, 0, 0);
	PI3DListAdd((PI3DList **)&importer->scene->meshList, reinterpret_cast<PI3DList *>(mesh));
	uint16 *objPathIn=(uint16*)importer->userData;
	
	#if WIN32
		wchar_t winPath[2048];
		PI3DStringCopy16W(winPath,objPathIn);
		FILE	*f = _wfopen(winPath, L"r");
	#else
		//¥¥¥Must fix this
		char macPath[2048];
		PI3DStringCopy16C(macPath,objPathIn);
		FILE	*f = fopen(macPath, "r");
	#endif
	if(!f)
	{
		delete [] line;
		delete [] token;
		delete [] str;
		delete [] currentMaterial;
		return 0;
	}		
	// load the mesh
	while (!feof(f))
	{
		ReadLine(f, MAX_LINE, line);
		PI3DTrimLeft(line);
		PI3DTrimRight(line);
		if (!PI3DSplitString(token, line, true, '\0' ))
			continue;

		if (strcmp(token, "mtllib") == 0) // material library
		{
			if (PI3DSplitString(token, line, true, '\0' ))
			{
				//const wchar_t	objPath[2048] = importer->bitStream->GetName();
				wchar_t			mtlPath[2048];
				PI3DStringCopy16W(mtlPath,objPathIn);
				//wcscpy(mtlPath, objPath);
				size_t i = wcslen(mtlPath);
				#if Macintosh
					wchar_t delimiter=L'/';
				#else
					wchar_t delimiter=L'\\';
					//wchar_t delimiter=(wchar_t)'\\';
				#endif	
				wchar_t currentCharacter=mtlPath[i - 1];
				while (currentCharacter != delimiter)
				{
					i--;
					if (i == 0)
						break;
					currentCharacter=mtlPath[i - 1];
				}
				mtlPath[i] = '\0';
				int32 j = 0;
				while (token[j] != '\0')
				{
					mtlPath[i++] = token[j++];
				}
				mtlPath[i] = '\0';
				LoadMaterialList(mtlPath, importer);
			}
		}
		else if (strcmp(token, "v") == 0) // vertex
		{
			PI3DVector	v = { 0.0, 0.0, 0.0 };

			if (PI3DSplitString(token, line, true, '\0' ))
			{
				sscanf(token, "%lf", &(v[0]));
				if (PI3DSplitString(token, line, true, '\0' ))
				{
					sscanf(token, "%lf", &(v[1]));
					if (PI3DSplitString(token, line, true, '\0' ))
					{
						sscanf(token, "%lf", &(v[2]));
					}
				}
			}
			if (!PI3DAddVertexToMesh(mesh, v, maxVertices))
				goto err;
		}
		else if (strcmp(token, "vn") == 0) // normal
		{
			PI3DVector	n = { 0.0, 0.0, 0.0 };

			if (PI3DSplitString(token, line, true, '\0' ))
			{
				sscanf(token, "%lf", &(n[0]));
				if (PI3DSplitString(token, line, true, '\0' ))
				{
					sscanf(token, "%lf", &(n[1]));
					if (PI3DSplitString(token, line, true, '\0' ))
					{
						sscanf(token, "%lf", &(n[2]));
					}
				}
			}
			if (!PI3DAddNormalToMesh(mesh, n, maxNormals))
				goto err;
		}
		else if (strcmp(token, "vt") == 0) // UV
		{
			PI3DPoint	uv = { 0.0, 0.0 };

			if (PI3DSplitString(token, line, true, '\0' ))
			{
				sscanf(token, "%lf", &(uv[0]));
				if (PI3DSplitString(token, line, true, '\0' ))
				{
					sscanf(token, "%lf", &(uv[1]));
				}
			}
			if (!PI3DAddUVToMesh(mesh, uv, maxUVs))
				goto err;
		}
		else if (strcmp(token, "f") == 0) // face
		{
			if (!readFaces)
				continue;

			int32		nPoints = 4;
			PI3DFace		f;

			f.flags = 0;
			f.numPoints = 0;
			f.points = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
			f.normals = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
			f.textures = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
			f.colors = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
			if (f.points == NULL || f.normals == NULL || f.textures == NULL || f.colors == NULL)
				goto err;
			f.smoothing = 1;
			f.material = currentMaterialID;
			while (PI3DSplitString(token, line, true, '\0' ))
			{
				if (f.numPoints == nPoints)
				{ // expand the list of points, normals, and UVs
					nPoints *= 2;
					int32	*newPoints = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
					int32	*newNormals = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
					int32	*newTextures = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
					int32	*newColors = (int32 *)PI3DMemoryAlloc(sizeof(int32) * nPoints);
					if (newPoints == NULL || newNormals == NULL || newTextures == NULL || newColors == NULL)
						goto err;
					for (int32 i = 0; i < f.numPoints; i++)
					{
						newPoints[i] = f.points[i];
						newNormals[i] = f.normals[i];
						newTextures[i] = f.textures[i];
						newColors[i] = f.colors[i];
					}
					PI3DMemoryFree(f.points);
					PI3DMemoryFree(f.normals);
					PI3DMemoryFree(f.textures);
					PI3DMemoryFree(f.colors);
					f.points = newPoints;
					f.normals = newNormals;
					f.textures = newTextures;
					f.colors = newColors;
				}
				f.points[f.numPoints] = 1;
				f.textures[f.numPoints] = 1;
				f.normals[f.numPoints] = 1;
				f.colors[f.numPoints] = 1;
				bool noUV = false;
				for (uint32 i = 0; i < strlen(token) - 1; i++)
				{
					if (token[i] == '/' && token[i + 1] == '/')
						noUV = true;
				}
				if (PI3DSplitString(str, token, false, '/'))
				{
					sscanf(str, "%d", &(f.points[f.numPoints]));
					if (PI3DSplitString(str, token, false, '/'))
					{
						if (noUV)
							sscanf(str, "%d", &(f.normals[f.numPoints]));
						else
							sscanf(str, "%d", &(f.textures[f.numPoints]));
						if (PI3DSplitString(str, token, false, '/'))
						{
							sscanf(str, "%d", &(f.normals[f.numPoints]));
						}
					}
				}
				// indices in OBJ are 1-based, but they are 0-based in Photoshop's scene structure
				f.points[f.numPoints]--;
				f.normals[f.numPoints]--;
				f.textures[f.numPoints]--;
				f.colors[f.numPoints]--;
				f.numPoints++;
			}
			if (!PI3DAddFaceToMesh(mesh, &f, maxFaces))
				goto err;
		}
		else if (strcmp(token, "o") == 0) // object
		{
			// not implemented (very optional)
		}
		else if (strcmp(token, "usemtl") == 0) // use a previously defined material
		{
			if (PI3DSplitString(currentMaterial, line, true, '\0' ))
			{
				PI3DMaterial	*mtl = PI3DUpdateMaterials(importer->scene, currentMaterial, 0);
				currentMaterialID = PI3DFindMaterial(importer->scene, mtl->name);
			}
		}
		else if (strcmp(token, "s") == 0) // smoothing group
		{
			// not implemented
		}
		else if (strcmp(token, "g") == 0) // group
		{
			// not implemented
		}
#ifdef _DEBUG
		else if (strcmp(token, "faces_off") == 0) // ignore faces (not a real OBJ marker - I use it for debugging)
		{
			readFaces = false;
		}
		else if (strcmp(token, "faces_on") == 0) // read faces again (not a real OBJ marker - I use it for debugging)
		{
			readFaces = true;
		}
		else if (strcmp(token, "eof") == 0) // end-of-file (not a real OBJ marker - I use it for debugging)
		{
			break;
		}
#endif
	}

	if (mesh->normals == 0)
		mesh->smoothingGroupPresent = true;

	PI3DDefaultLights(importer->scene);

	fclose(f);

	delete [] line;
	delete [] token;
	delete [] str;
	delete [] currentMaterial;
	
	return 1;
err:

	delete [] line;
	delete [] token;
	delete [] str;
	delete [] currentMaterial;

	PI3DKillScene(importer->scene);
	fclose(f);
	return 0;
}