コード例 #1
0
ファイル: smdfile.cpp プロジェクト: MGraefe/deferred
error_e parseTriangleBlock(char *start, std::vector<rpm_triangle_t> &tris, std::vector<std::string> &textures, std::vector<int> &parentBones)
{
	static const char triBlockStart[] = "\ntriangles\n";
	start = strstr( start, triBlockStart );
	if(!start)
		return ERR_CORRUPT_FILE;
	start += strlen(triBlockStart);

	while(true)
	{
		//read texture name
		char texname[256];
		start = CopyUntilOccurenceOfChar(texname, start, "\n");
		if( strcmp(texname, "end") == 0 )
			break;

		//Get texture id
		int texId = getTextureIndex(textures, texname);
		if( texId < 0 )
		{
			textures.push_back(std::string(texname));
			texId = textures.size()-1;
		}

		start = parseTriangle(start, tris, texId, parentBones);
	}

	return ERR_NONE;
}
コード例 #2
0
ファイル: scene_parser.cpp プロジェクト: ChanganVR/ray-tracer
Object3D* SceneParser::parseObject(char token[MAX_PARSER_TOKEN_LENGTH]) {
	Object3D *answer = NULL;
	if (!strcmp(token, "Group")) {
		answer = (Object3D*)parseGroup();
	}
	else if (!strcmp(token, "Sphere")) {
		answer = (Object3D*)parseSphere();
	}
	else if (!strcmp(token, "Plane")) {
		answer = (Object3D*)parsePlane();
	}
	else if (!strcmp(token, "Triangle")) {
		answer = (Object3D*)parseTriangle();
	}
	else if (!strcmp(token, "TriangleMesh")) {
		answer = (Object3D*)parseTriangleMesh();
	}
	else if (!strcmp(token, "Transform")) {
		answer = (Object3D*)parseTransform();
	}
	else {
		printf("Unknown token in parseObject: '%s'\n", token);
		exit(0);
	}
	return answer;
}
コード例 #3
0
ファイル: scene.cpp プロジェクト: TomDunn/Proj3
/* Parses the "Group" token */
rtObjGroup* scene::parseGroup()
{
    char token[MAX_PARSER_TOKEN_LENGTH];


    getToken(token);
    assert (!strcmp(token, "{"));

    /**********************************************/
    /* Instantiate the group object               */
    /**********************************************/
    rtObjGroup *answer     = new rtObjGroup();

    bool working=true;
    while (working)
    {
        getToken(token);
        if (!strcmp(token,"}"))
        {
            working=false;
        }
        else
        {
            if (!strcmp(token, "Sphere"))
            {
                sphere *sceneElem = parseSphere();
                assert(sceneElem != NULL);
                answer->addObj(sceneElem);
            }
            else if (!strcmp(token, "Triangle"))
            {
                triangle *sceneElem = parseTriangle();
                assert(sceneElem != NULL);
                answer->addObj(sceneElem);
            }
            else
            {
                cout << "Unknown token in Group: '" << token << "' at line "
                     << curline << "\n";
                exit(0);
            }
        }
    }

    /* Return the group */
    return answer;
}
コード例 #4
0
ファイル: fileIO.c プロジェクト: PuzzleBot/RayRenderer
void parseFile(char * inputFilePath){
    FILE * fp = fopen(inputFilePath, "r");
    char inputBuffer[2048];
    char * shapeToken = NULL;
    int lineCounter = 0;

    GLfloat currentReflection = 0.0;
    GLfloat currentOpacity = 1.0;
    GLfloat currentRefractIndex = 1.0;

    if(fp == NULL){
        printf("Error could not open the file %s", inputFilePath);
        deallocExit(0);
    }

    do{
        fgets(inputBuffer, 2048, fp);
        if(strlen(inputBuffer) > 1){
            shapeToken = strtok(inputBuffer, PARSE_DELIMITERS);

            if(strcmp(shapeToken, "triangle") == 0){
                parseTriangle(currentRefractIndex);
            }
            else if(strcmp(shapeToken, "sphere") == 0){
                parseSphere(currentRefractIndex);
            }
            else if(strcmp(shapeToken, "light") == 0){
                parseLight();
            }
            else if(strcmp(shapeToken, "lens") == 0){
                parseLens();
            }
            else{
                /*Lines starting with '#' are comments, and are ignored*/
                if(shapeToken[0] != '#'){
                    printf("Warning: Ignoring unrecognized input on line %d.\n", lineCounter);
                }
            }
        }
        lineCounter++;
    }
    while((feof(fp) == 0) && (ferror(fp) == 0));

    sortLensList();

}
コード例 #5
0
ファイル: sceneParser.cpp プロジェクト: tritenour01/raytracer
void SceneParser::parseObjects(void)
{
    if(currentToken == Scanner::StreamDone)
        return;
    else{
        while(errorFlag == false && currentToken != Scanner::StreamDone)
        {
            acceptToken(Scanner::Id);
            string tokenText = scanner.tokenText();

            if(tokenText == "sphere")
                parseSphere();
            else if(tokenText == "box")
                parseBox();
            else if(tokenText == "plane")
                parsePlane();
            else if(tokenText == "triangle")
                parseTriangle();
            else if(tokenText == "mesh")
                parseMesh();
            else if(tokenText == "cone")
                parseCone();
            else if(tokenText == "cylinder")
                parseCylinder();
            else if(tokenText == "pointlight")
                parsePointLight();
            else if(tokenText == "directionallight")
                parseDirectionalLight();
            else if(tokenText == "spotlight")
                parseSpotlight();
            else if(tokenText == "arealight")
                parseAreaLight();
            else{
                error("undefined command: " + tokenText);
            }

            advance();
        }
    }
}
コード例 #6
0
Scene parseFile( std::string filename )
{
   Scene scene;
   int maxSpheres = 1000;
   int maxTriangles = 1000;
   int maxPlanes = 1000;
   int maxPointLights = 10;
   scene.numPointLights = 0;
   scene.numSpheres = 0;
   scene.numTriangles = 0;
   scene.numPlanes = 0;
   scene.spheres = (Sphere *)malloc( sizeof(Sphere) * maxSpheres );
   scene.triangles = (Triangle *)malloc( sizeof(Triangle) * maxTriangles );
   scene.planes = (Plane *)malloc( sizeof(Plane) * maxSpheres );
   scene.pointLights = (PointLight *)malloc( sizeof(PointLight) * maxPointLights );

   //Open file for writing
   FILE *file = fopen(filename.c_str(), "r");
   if(file == NULL)
   {
      printf("Error Occured opening file\n");
      exit(EXIT_FAILURE);
   }

   while(1)
   {
      //starting off eating all whitespace
      char cur = ' ';
      while( isspace(cur) )
      {
         if( fscanf( file, "%c", &cur ) == EOF )
         {
            printf("End of File reached\n");
            return scene;
         }
      }

      //check for comment
      if(cur == '/')
      {
         while(cur != '\n')
         {
            if( fscanf( file, "%c", &cur ) == EOF )
            {
               printf("Error Occured reading file\n");
               exit(EXIT_FAILURE);
            }
         }
      }
      else if( cur == 'c' || cur == 'C' )
      {
         scene.camera = parseCamera( file );
      }
      else if( cur == 'l' || cur == 'L' )
      {
         PointLight light = parsePointLight( file );
         if( scene.numPointLights + 1 >= maxPointLights )
         {
            maxPointLights = maxPointLights*10;
            scene.pointLights = (PointLight *)realloc( scene.pointLights, sizeof(PointLight)*maxPointLights );
         }
         scene.pointLights[scene.numPointLights] = light;
         scene.numPointLights++;
      }
      else if( cur == 's' || cur == 'S' )
      {
         if( scene.numSpheres+1 >= maxSpheres )
         {
            maxSpheres = maxSpheres*1000;
            scene.spheres = (Sphere *) realloc( scene.spheres, sizeof(Sphere) * maxSpheres );
         }
         scene.spheres[scene.numSpheres] = parseSphere(file);
         scene.numSpheres++;
      }
      else if( cur == 'p' || cur == 'P' )
      {
         if( scene.numPlanes+1 >= maxPlanes )
         {
            maxPlanes = maxPlanes*1000;
            scene.planes = (Plane *) realloc( scene.planes, maxPlanes * sizeof(Plane) );
         }
         scene.planes[scene.numPlanes] = parsePlane(file);
         scene.numPlanes++;
      }
      else if( cur == 't' || cur == 'T' )
      {
         if( scene.numTriangles+1 >= maxTriangles )
         {
            maxTriangles = maxTriangles*1000;
            scene.triangles = (Triangle *) realloc( scene.triangles, maxTriangles * sizeof(Triangle) );
         }
         scene.triangles[scene.numTriangles] = parseTriangle(file);
         scene.numTriangles++;
      }
      else
      {
         printf("Unknown Keyword Failure char was |%c|\n", cur);
         exit(EXIT_FAILURE);
      }
   }
}
コード例 #7
0
ファイル: LDModelParser.cpp プロジェクト: HazenBabcock/LDView
bool LDModelParser::parseModel(
	LDLModel *ldlModel,
	TREModel *treModel,
	bool bfc,
	int activeColorNumber)
{
	BFCState newState = ldlModel->getBFCState();
	LDObiInfo obiInfo;
	LDObiInfo *origObiInfo = m_obiInfo;

	if (m_obiInfo != NULL && m_obiInfo->isActive() &&
		!ldlModel->colorNumberIsTransparent(activeColorNumber))
	{
		obiInfo.start(m_obiInfo->getColor(), m_obiInfo->getEdgeColor(), true);
	}
	m_obiInfo = &obiInfo;
	bfc = ((bfc && (newState == BFCOnState)) || newState == BFCForcedOnState)
		&& getBFCFlag();
	if (ldlModel && !performPrimitiveSubstitution(ldlModel, treModel,
		activeColorNumber, bfc))
	{
		LDLFileLineArray *fileLines = ldlModel->getFileLines();

		if (fileLines)
		{
			int i;
			int count = ldlModel->getActiveLineCount();
			StringSet obiOrigTokens = m_obiTokens;

			for (i = 0; i < count && !m_abort; i++)
			{
				LDLFileLine *fileLine = (*fileLines)[i];

				if (fileLine->isValid())
				{
					if (fileLine->isActionLine() &&
						actionLineIsActive((LDLActionLine *)fileLine))
					{
						if (m_flags.newTexmap)
						{
							treModel->startTexture(fileLine->getTexmapType(),
								fileLine->getTexmapFilename(),
								fileLine->getTexmapImage(),
								fileLine->getTexmapPoints());
							m_flags.newTexmap = false;
							m_flags.texmapStarted = true;
						}
						//if (m_flags.obi)
						//{
						//	((LDLActionLine *)fileLine)->setObiOverrideActive(
						//		!ldlModel->colorNumberIsTransparent(
						//		activeColorNumber));
						//}
						switch (fileLine->getLineType())
						{
						case LDLLineTypeModel:
							parseModel((LDLModelLine *)fileLine, treModel, bfc,
								activeColorNumber);
							break;
						case LDLLineTypeLine:
							parseLine((LDLShapeLine *)fileLine, treModel,
								activeColorNumber);
							break;
						case LDLLineTypeTriangle:
							parseTriangle((LDLShapeLine *)fileLine, treModel,
								bfc, false, activeColorNumber);
							break;
						case LDLLineTypeQuad:
							parseQuad((LDLShapeLine *)fileLine, treModel, bfc,
								false, activeColorNumber);
							break;
						case LDLLineTypeConditionalLine:
							parseConditionalLine(
								(LDLConditionalLineLine *)fileLine, treModel,
								activeColorNumber);
							break;
						default:
							break;
						}
						m_obiInfo->actionHappened();
						if (m_flags.texmapNext)
						{
							treModel->endTexture();
						}
					}
					else if (fileLine->getLineType() == LDLLineTypeComment)
					{
						parseCommentLine((LDLCommentLine *)fileLine, treModel);
					}
				}
				if (ldlModel == m_topLDLModel && m_alertSender != NULL)
				{
					TCProgressAlert::send("LDLModelParser",
						TCLocalStrings::get(_UC("ParsingStatus")),
						(float)(i + 1) / (float)(count + 1), &m_abort, this);
				}
			}
			m_obiTokens = obiOrigTokens;
		}
	}
	m_obiInfo = origObiInfo;
	return !m_abort;
}