예제 #1
0
파일: model.cpp 프로젝트: Hellzed/xoreos
void Model::finalize() {
	_currentState = 0;

	createStateNamesList();
	setState();

	createBound();

	// Order all node children lists
	for (StateList::iterator s = _stateList.begin(); s != _stateList.end(); ++s)
		for (NodeList::iterator n = (*s)->rootNodes.begin(); n != (*s)->rootNodes.end(); ++n)
			(*n)->orderChildren();

	needRebuild();
}
예제 #2
0
bool BreakoutMainScene::init()
{
    if(!Layer::init())
    {
        return false;
    }

    score = 0;
    checkLoseFlag = false;
    checkMissBall = false;

    createBound();
    createBall();
    createPaddle();
    createBlock();

    auto listener = EventListenerTouchOneByOne::create();

    listener->onTouchBegan = CC_CALLBACK_2(BreakoutMainScene::onTouchBegan , this);
    listener->onTouchMoved = CC_CALLBACK_2(BreakoutMainScene::onTouchMoved , this);
    listener->onTouchEnded = CC_CALLBACK_2(BreakoutMainScene::onTouchEnded , this);
    listener->onTouchCancelled = CC_CALLBACK_2(BreakoutMainScene::onTouchCancelled , this);

    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener , this);


    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto contactListener = EventListenerPhysicsContact::create();
    contactListener->onContactBegin = CC_CALLBACK_1(BreakoutMainScene::onContactBegin , this);

    dispatcher->addEventListenerWithSceneGraphPriority(contactListener , this);


    this->schedule(schedule_selector(BreakoutMainScene::updateGame) , 3.0f);

    return true;
}
예제 #3
0
void ModelNode_Witcher::readTexturePaint(Model_Witcher::ParserContext &ctx) {
	uint32 layersOffset, layersCount;
	Model::readArrayDef(*ctx.mdb, layersOffset, layersCount);

	ctx.mdb->skip(28); // Unknown

	uint32 offMeshArrays = ctx.mdb->readUint32LE();

	uint32 sectorID0 = ctx.mdb->readUint32LE();
	uint32 sectorID1 = ctx.mdb->readUint32LE();
	uint32 sectorID2 = ctx.mdb->readUint32LE();
	uint32 sectorID3 = ctx.mdb->readUint32LE();

	float boundingMin[3], boundingMax[3];

	boundingMin[0] = ctx.mdb->readIEEEFloatLE();
	boundingMin[1] = ctx.mdb->readIEEEFloatLE();
	boundingMin[2] = ctx.mdb->readIEEEFloatLE();

	boundingMax[0] = ctx.mdb->readIEEEFloatLE();
	boundingMax[1] = ctx.mdb->readIEEEFloatLE();
	boundingMax[2] = ctx.mdb->readIEEEFloatLE();

	_diffuse[0] = ctx.mdb->readIEEEFloatLE();
	_diffuse[1] = ctx.mdb->readIEEEFloatLE();
	_diffuse[2] = ctx.mdb->readIEEEFloatLE();
	_ambient[0] = ctx.mdb->readIEEEFloatLE();
	_ambient[1] = ctx.mdb->readIEEEFloatLE();
	_ambient[2] = ctx.mdb->readIEEEFloatLE();

	float textureTransRot[3];
	textureTransRot[0] = ctx.mdb->readIEEEFloatLE();
	textureTransRot[1] = ctx.mdb->readIEEEFloatLE();
	textureTransRot[2] = ctx.mdb->readIEEEFloatLE();

	_shadow = ctx.mdb->readUint32LE() == 1;
	_render = ctx.mdb->readUint32LE() == 1;

	bool tileFade = ctx.mdb->readUint32LE() == 1;

	bool controlFade   = ctx.mdb->readByte() == 1;
	bool lightMapped   = ctx.mdb->readByte() == 1;
	bool rotateTexture = ctx.mdb->readByte() == 1;
	ctx.mdb->skip(1); // Unknown

	float transparencyShift = ctx.mdb->readIEEEFloatLE();

	uint32 defaultRenderList = ctx.mdb->readUint32LE();
	uint32 fourCC            = ctx.mdb->readUint32BE();

	ctx.mdb->skip(4); // Unknown

	float depthOffset = ctx.mdb->readIEEEFloatLE();

	uint32 blendGroup = ctx.mdb->readUint32LE();

	bool dayNightLightMaps = ctx.mdb->readByte() == 1;

	Common::UString dayNightTransition = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 200);

	bool ignoreHitCheck  = ctx.mdb->readByte() == 1;
	bool needsReflection = ctx.mdb->readByte() == 1;
	ctx.mdb->skip(1); // Unknown

	float reflectionPlaneNormal[3];
	reflectionPlaneNormal[0] = ctx.mdb->readIEEEFloatLE();
	reflectionPlaneNormal[1] = ctx.mdb->readIEEEFloatLE();
	reflectionPlaneNormal[2] = ctx.mdb->readIEEEFloatLE();

	float reflectionPlaneDistance = ctx.mdb->readIEEEFloatLE();

	bool fadeOnCameraCollision = ctx.mdb->readByte() == 1;
	bool noSelfShadow          = ctx.mdb->readByte() == 1;
	bool isReflected           = ctx.mdb->readByte() == 1;
	ctx.mdb->skip(1); // Unknown

	float detailMapScape = ctx.mdb->readIEEEFloatLE();

	bool onlyReflected = ctx.mdb->readByte() == 1;

	Common::UString lightMapName = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64);

	bool canDecal            = ctx.mdb->readByte() == 1;
	bool ignoreLODReflection = ctx.mdb->readByte() == 1;
	bool enableSpecular      = ctx.mdb->readByte() == 1;


	uint32 endPos = ctx.mdb->seek(ctx.offRawData + offMeshArrays);

	ctx.mdb->skip(4);

	uint32 vertexOffset, vertexCount;
	Model::readArrayDef(*ctx.mdb, vertexOffset, vertexCount);

	uint32 normalsOffset, normalsCount;
	Model::readArrayDef(*ctx.mdb, normalsOffset, normalsCount);

	uint32 tangentsOffset, tangentsCount;
	Model::readArrayDef(*ctx.mdb, tangentsOffset, tangentsCount);

	uint32 biNormalsOffset, biNormalsCount;
	Model::readArrayDef(*ctx.mdb, biNormalsOffset, biNormalsCount);

	uint32 tVertsOffset[4], tVertsCount[4];
	for (uint t = 0; t < 4; t++)
		Model::readArrayDef(*ctx.mdb, tVertsOffset[t], tVertsCount[t]);

	uint32 unknownOffset, unknownCount;
	Model::readArrayDef(*ctx.mdb, unknownOffset, unknownCount);

	uint32 facesOffset, facesCount;
	Model::readArrayDef(*ctx.mdb, facesOffset, facesCount);

	if ((vertexCount == 0) || (facesCount == 0)) {
		ctx.mdb->seek(endPos);
		return;
	}

	std::vector<TexturePaintLayer> layers;
	layers.resize(layersCount);

	for (uint32 l = 0; l < layersCount; l++) {
		ctx.mdb->seek(ctx.offRawData + layersOffset + l * 52);

		layers[l].hasTexture = ctx.mdb->readByte() == 1;
		if (!layers[l].hasTexture)
			continue;

		ctx.mdb->skip(3); // Unknown
		ctx.mdb->skip(4); // Offset to material

		layers[l].texture = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

		uint32 weightsOffset, weightsCount;
		Model::readArrayDef(*ctx.mdb, weightsOffset, weightsCount);

		ctx.mdb->seek(ctx.offRawData + weightsOffset);
		layers[l].weights.resize(weightsCount);

		for (std::vector<float>::iterator w = layers[l].weights.begin(); w != layers[l].weights.end(); ++w)
			*w = ctx.mdb->readIEEEFloatLE();
	}

	std::vector<Common::UString> textures;
	textures.push_back(lightMapName);

	evaluateTextures(1, textures, 0, tVertsCount, dayNightLightMaps, lightMapName);

	loadTextures(textures);

	size_t texCount = textures.size();

	// Read vertices

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	for (uint t = 0; t < texCount; t++)
		vertexDecl.push_back(VertexAttrib(VTCOORD + t, 2, GL_FLOAT));

	_vertexBuffer.setVertexDeclLinear(vertexCount, vertexDecl);

	// Read vertex position
	ctx.mdb->seek(ctx.offRawData + vertexOffset);
	float *v = reinterpret_cast<float *>(_vertexBuffer.getData(0));
	for (uint32 i = 0; i < vertexCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read vertex normals
	assert(normalsCount == vertexCount);
	ctx.mdb->seek(ctx.offRawData + normalsOffset);
	v = reinterpret_cast<float *>(_vertexBuffer.getData(1));
	for (uint32 i = 0; i < normalsCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read texture coordinates
	for (uint t = 0; t < texCount; t++) {

		ctx.mdb->seek(ctx.offRawData + tVertsOffset[t]);
		v = reinterpret_cast<float *>(_vertexBuffer.getData(2 + t));
		for (uint32 i = 0; i < tVertsCount[t]; i++) {
			if (i < tVertsCount[t]) {
				*v++ = ctx.mdb->readIEEEFloatLE();
				*v++ = ctx.mdb->readIEEEFloatLE();
			} else {
				*v++ = 0.0f;
				*v++ = 0.0f;
			}
		}
	}


	// Read faces

	_indexBuffer.setSize(facesCount * 3, sizeof(uint32), GL_UNSIGNED_INT);

	ctx.mdb->seek(ctx.offRawData + facesOffset);
	uint32 *f = reinterpret_cast<uint32 *>(_indexBuffer.getData());
	for (uint32 i = 0; i < facesCount; i++) {
		// Vertex indices
		*f++ = ctx.mdb->readUint32LE();
		*f++ = ctx.mdb->readUint32LE();
		*f++ = ctx.mdb->readUint32LE();

		ctx.mdb->skip(68); // Unknown
	}

	createBound();

	ctx.mdb->seek(endPos);
}
예제 #4
0
void ModelNode_Witcher::readMesh(Model_Witcher::ParserContext &ctx) {
	ctx.mdb->skip(4); // Function pointer
	ctx.mdb->skip(4); // Unknown

	uint32 offMeshArrays = ctx.mdb->readUint32LE();

	ctx.mdb->skip(4); // Unknown

	float boundingMin[3], boundingMax[3];

	boundingMin[0] = ctx.mdb->readIEEEFloatLE();
	boundingMin[1] = ctx.mdb->readIEEEFloatLE();
	boundingMin[2] = ctx.mdb->readIEEEFloatLE();

	boundingMax[0] = ctx.mdb->readIEEEFloatLE();
	boundingMax[1] = ctx.mdb->readIEEEFloatLE();
	boundingMax[2] = ctx.mdb->readIEEEFloatLE();

	ctx.mdb->skip(28); // Unknown

	float volFogScale = ctx.mdb->readIEEEFloatLE();

	ctx.mdb->skip(16); // Unknown

	_diffuse[0] = ctx.mdb->readIEEEFloatLE();
	_diffuse[1] = ctx.mdb->readIEEEFloatLE();
	_diffuse[2] = ctx.mdb->readIEEEFloatLE();
	_ambient[0] = ctx.mdb->readIEEEFloatLE();
	_ambient[1] = ctx.mdb->readIEEEFloatLE();
	_ambient[2] = ctx.mdb->readIEEEFloatLE();

	float textureTransRot[3];
	textureTransRot[0] = ctx.mdb->readIEEEFloatLE();
	textureTransRot[1] = ctx.mdb->readIEEEFloatLE();
	textureTransRot[2] = ctx.mdb->readIEEEFloatLE();

	_shininess = ctx.mdb->readIEEEFloatLE();

	_shadow  = ctx.mdb->readUint32LE() == 1;
	_beaming = ctx.mdb->readUint32LE() == 1;
	_render  = ctx.mdb->readUint32LE() == 1;

	_hasTransparencyHint = true;
	_transparencyHint    = ctx.mdb->readUint32LE() == 1;

	ctx.mdb->skip(4); // Unknown

	Common::UString texture[4];
	for (int t = 0; t < 4; t++) {
		texture[t] = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64);

		if (texture[t] == "NULL")
			texture[t].clear();
	}

	bool tileFade = ctx.mdb->readUint32LE() == 1;

	bool controlFade   = ctx.mdb->readByte() == 1;
	bool lightMapped   = ctx.mdb->readByte() == 1;
	bool rotateTexture = ctx.mdb->readByte() == 1;

	ctx.mdb->skip(1); // Unknown

	float transparencyShift = ctx.mdb->readIEEEFloatLE();

	uint32 defaultRenderList = ctx.mdb->readUint32LE();
	uint32 preserveVColors   = ctx.mdb->readUint32LE();

	uint32 fourCC = ctx.mdb->readUint32BE();

	ctx.mdb->skip(4); // Unknown

	float depthOffset       = ctx.mdb->readIEEEFloatLE();
	float coronaCenterMult  = ctx.mdb->readIEEEFloatLE();
	float fadeStartDistance = ctx.mdb->readIEEEFloatLE();

	bool distFromScreenCenterFace = ctx.mdb->readByte() == 1;
	ctx.mdb->skip(3); // Unknown

	float enlargeStartDistance = ctx.mdb->readIEEEFloatLE();

	bool affectedByWind = ctx.mdb->readByte() == 1;
	ctx.mdb->skip(3); // Unknown

	float dampFactor = ctx.mdb->readIEEEFloatLE();

	uint32 blendGroup = ctx.mdb->readUint32LE();

	bool dayNightLightMaps = ctx.mdb->readByte() == 1;

	Common::UString dayNightTransition = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 200);

	bool ignoreHitCheck  = ctx.mdb->readByte() == 1;
	bool needsReflection = ctx.mdb->readByte() == 1;
	ctx.mdb->skip(1); // Unknown

	float reflectionPlaneNormal[3];
	reflectionPlaneNormal[0] = ctx.mdb->readIEEEFloatLE();
	reflectionPlaneNormal[1] = ctx.mdb->readIEEEFloatLE();
	reflectionPlaneNormal[2] = ctx.mdb->readIEEEFloatLE();

	float reflectionPlaneDistance = ctx.mdb->readIEEEFloatLE();

	bool fadeOnCameraCollision = ctx.mdb->readByte() == 1;
	bool noSelfShadow          = ctx.mdb->readByte() == 1;
	bool isReflected           = ctx.mdb->readByte() == 1;
	bool onlyReflected         = ctx.mdb->readByte() == 1;

	Common::UString lightMapName = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64);

	bool canDecal            = ctx.mdb->readByte() == 1;
	bool multiBillBoard      = ctx.mdb->readByte() == 1;
	bool ignoreLODReflection = ctx.mdb->readByte() == 1;
	ctx.mdb->skip(1); // Unknown

	float detailMapScape = ctx.mdb->readIEEEFloatLE();

	ctx.offTextureInfo = ctx.mdb->readUint32LE();

	uint32 endPos = ctx.mdb->seek(ctx.offRawData + offMeshArrays);

	ctx.mdb->skip(4);

	uint32 vertexOffset, vertexCount;
	Model::readArrayDef(*ctx.mdb, vertexOffset, vertexCount);

	uint32 normalsOffset, normalsCount;
	Model::readArrayDef(*ctx.mdb, normalsOffset, normalsCount);

	uint32 tangentsOffset, tangentsCount;
	Model::readArrayDef(*ctx.mdb, tangentsOffset, tangentsCount);

	uint32 biNormalsOffset, biNormalsCount;
	Model::readArrayDef(*ctx.mdb, biNormalsOffset, biNormalsCount);

	uint32 tVertsOffset[4], tVertsCount[4];
	for (uint t = 0; t < 4; t++)
		Model::readArrayDef(*ctx.mdb, tVertsOffset[t], tVertsCount[t]);

	uint32 unknownOffset, unknownCount;
	Model::readArrayDef(*ctx.mdb, unknownOffset, unknownCount);

	uint32 facesOffset, facesCount;
	Model::readArrayDef(*ctx.mdb, facesOffset, facesCount);

	if (ctx.fileVersion == 133)
		ctx.offTexData = ctx.mdb->readUint32LE();


	if ((vertexCount == 0) || (facesCount == 0)) {
		ctx.mdb->seek(endPos);
		return;
	}

	std::vector<Common::UString> textures;
	readTextures(ctx, textures);

	evaluateTextures(4, textures, texture, tVertsCount, dayNightLightMaps, lightMapName);

	loadTextures(textures);

	size_t texCount = textures.size();

	// Read vertices

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	for (uint t = 0; t < texCount; t++)
		vertexDecl.push_back(VertexAttrib(VTCOORD + t, 2, GL_FLOAT));

	_vertexBuffer.setVertexDeclLinear(vertexCount, vertexDecl);

	// Read vertex position
	ctx.mdb->seek(ctx.offRawData + vertexOffset);
	float *v = reinterpret_cast<float *>(_vertexBuffer.getData(0));
	for (uint32 i = 0; i < vertexCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read vertex normals
	assert(normalsCount == vertexCount);
	ctx.mdb->seek(ctx.offRawData + normalsOffset);
	v = reinterpret_cast<float *>(_vertexBuffer.getData(1));
	for (uint32 i = 0; i < normalsCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read texture coordinates
	for (uint t = 0; t < texCount; t++) {

		ctx.mdb->seek(ctx.offRawData + tVertsOffset[t]);
		v = reinterpret_cast<float *>(_vertexBuffer.getData(2 + t));
		for (uint32 i = 0; i < tVertsCount[t]; i++) {
			if (i < tVertsCount[t]) {
				*v++ = ctx.mdb->readIEEEFloatLE();
				*v++ = ctx.mdb->readIEEEFloatLE();
			} else {
				*v++ = 0.0f;
				*v++ = 0.0f;
			}
		}
	}


	// Read faces

	_indexBuffer.setSize(facesCount * 3, sizeof(uint32), GL_UNSIGNED_INT);

	ctx.mdb->seek(ctx.offRawData + facesOffset);
	uint32 *f = reinterpret_cast<uint32 *>(_indexBuffer.getData());
	for (uint32 i = 0; i < facesCount; i++) {
		ctx.mdb->skip(4 * 4 + 4);

		if (ctx.fileVersion == 133)
			ctx.mdb->skip(3 * 4);

		// Vertex indices
		*f++ = ctx.mdb->readUint32LE();
		*f++ = ctx.mdb->readUint32LE();
		*f++ = ctx.mdb->readUint32LE();

		if (ctx.fileVersion == 133)
			ctx.mdb->skip(4);
	}

	createBound();

	ctx.mdb->seek(endPos);
}
예제 #5
0
void ModelNode_KotOR::readMesh(Model_KotOR::ParserContext &ctx) {
	uint32 P = ctx.mdl->pos();

	ctx.mdl->skip(8); // Function pointers

	uint32 facesOffset, facesCount;
	Model::readArrayDef(*ctx.mdl, facesOffset, facesCount);

	float boundingMin[3], boundingMax[3];

	boundingMin[0] = ctx.mdl->readIEEEFloatLE();
	boundingMin[1] = ctx.mdl->readIEEEFloatLE();
	boundingMin[2] = ctx.mdl->readIEEEFloatLE();

	boundingMax[0] = ctx.mdl->readIEEEFloatLE();
	boundingMax[1] = ctx.mdl->readIEEEFloatLE();
	boundingMax[2] = ctx.mdl->readIEEEFloatLE();

	float radius = ctx.mdl->readIEEEFloatLE();

	float pointsAverage[3];
	pointsAverage[0] = ctx.mdl->readIEEEFloatLE();
	pointsAverage[1] = ctx.mdl->readIEEEFloatLE();
	pointsAverage[2] = ctx.mdl->readIEEEFloatLE();

	_diffuse[0] = ctx.mdl->readIEEEFloatLE();
	_diffuse[1] = ctx.mdl->readIEEEFloatLE();
	_diffuse[2] = ctx.mdl->readIEEEFloatLE();

	_ambient[0] = ctx.mdl->readIEEEFloatLE();
	_ambient[1] = ctx.mdl->readIEEEFloatLE();
	_ambient[2] = ctx.mdl->readIEEEFloatLE();

	_specular[0] = 0;
	_specular[1] = 0;
	_specular[2] = 0;

	uint32 transparencyHint = ctx.mdl->readUint32LE();

	_hasTransparencyHint = true;
	_transparencyHint    = (transparencyHint != 0);

	std::vector<Common::UString> textures;

	textures.push_back(Common::readStringFixed(*ctx.mdl, Common::kEncodingASCII, 32));
	textures.push_back(Common::readStringFixed(*ctx.mdl, Common::kEncodingASCII, 32));

	ctx.mdl->skip(24); // Unknown

	ctx.mdl->skip(12); // Vertex indices counts

	uint32 offOffVerts, offOffVertsCount;
	Model::readArrayDef(*ctx.mdl, offOffVerts, offOffVertsCount);

	if (offOffVertsCount > 1)
		throw Common::Exception("Face offsets offsets count wrong (%d)", offOffVertsCount);

	ctx.mdl->skip(12); // Unknown

	ctx.mdl->skip(24 + 16); // Unknown

	uint32 mdxStructSize = ctx.mdl->readUint32LE();

	ctx.mdl->skip(8); // Unknown

	uint32 offNormals = ctx.mdl->readUint32LE();

	ctx.mdl->skip(4); // Unknown

	uint32 offUV[2];
	offUV[0] = ctx.mdl->readUint32LE();
	offUV[1] = ctx.mdl->readUint32LE();

	ctx.mdl->skip(24); // Unknown

	uint16 vertexCount  = ctx.mdl->readUint16LE();
	uint16 textureCount = ctx.mdl->readUint16LE();

	ctx.mdl->skip(2);

	byte unknownFlag1 = ctx.mdl->readByte();
	_shadow  = ctx.mdl->readByte() == 1;
	byte unknownFlag2 = ctx.mdl->readByte();
	_render  = ctx.mdl->readByte() == 1;

	ctx.mdl->skip(10);

	if (ctx.kotor2)
		ctx.mdl->skip(8);

	uint32 offNodeData = ctx.mdl->readUint32LE();

	ctx.mdl->skip(4);

	if ((offOffVertsCount < 1) || (vertexCount == 0) || (facesCount == 0))
		return;

	uint32 endPos = ctx.mdl->pos();

	if (textureCount > 2) {
		warning("Model_KotOR::readMesh(): textureCount > 2 (%d)", textureCount);
		textureCount = 2;
	}

	if ((textureCount > 0) && !ctx.texture.empty())
		textures[0] = ctx.texture;

	textures.resize(textureCount);
	loadTextures(textures);


	// Read vertices (interleaved)

	GLsizei vpsize = 3;
	GLsizei vnsize = 3;
	GLsizei vtsize = 2;
	uint32 vertexSize = (vpsize + vnsize + vtsize * textureCount) * sizeof(float);
	_vertexBuffer.setSize(vertexCount, vertexSize);

	float *vertexData = (float *) _vertexBuffer.getData();
	VertexDecl vertexDecl;

	VertexAttrib vp;
	vp.index = VPOSITION;
	vp.size = vpsize;
	vp.type = GL_FLOAT;
	vp.stride = vertexSize;
	vp.pointer = vertexData;
	vertexDecl.push_back(vp);

	VertexAttrib vn;
	vn.index = VNORMAL;
	vn.size = vnsize;
	vn.type = GL_FLOAT;
	vn.stride = vertexSize;
	vn.pointer = vertexData + vpsize;
	vertexDecl.push_back(vn);

	for (uint16 t = 0; t < textureCount; t++) {
		VertexAttrib vt;
		vt.index = VTCOORD + t;
		vt.size = vtsize;
		vt.type = GL_FLOAT;
		vt.stride = vertexSize;
		vt.pointer = vertexData + vpsize + vnsize + vtsize * t;
		vertexDecl.push_back(vt);
	}

	_vertexBuffer.setVertexDecl(vertexDecl);

	float *v = vertexData;
	for (uint32 i = 0; i < vertexCount; i++) {
		// Position
		ctx.mdx->seekTo(offNodeData + i * mdxStructSize);
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();

		// Normal
		//ctx.mdx->seekTo(offNodeData + i * mdxStructSize + offNormals);
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();

		// TexCoords
		for (uint16 t = 0; t < textureCount; t++) {
			if (offUV[t] != 0xFFFFFFFF) {
				ctx.mdx->seekTo(offNodeData + i * mdxStructSize + offUV[t]);
				*v++ = ctx.mdx->readIEEEFloatLE();
				*v++ = ctx.mdx->readIEEEFloatLE();
			} else {
				*v++ = 0.0;
				*v++ = 0.0;
			}
		}
	}


	// Read faces

	ctx.mdl->seekTo(ctx.offModelData + offOffVerts);
	uint32 offVerts = ctx.mdl->readUint32LE();

	ctx.mdl->seekTo(ctx.offModelData + offVerts);

	_indexBuffer.setSize(facesCount * 3, sizeof(uint16), GL_UNSIGNED_SHORT);

	uint16 *f = (uint16 *) _indexBuffer.getData();
	for (uint32 i = 0; i < facesCount * 3; i++)
		f[i] = ctx.mdl->readUint16LE();

	createBound();

	ctx.mdl->seekTo(endPos);
}
예제 #6
0
파일: lexer.c 프로젝트: SemiSQ/OpenModelica
static int yylex0()
{
	int i, c, d, e, token;

	struct Token *val;

	static char ident[LEXER_IDENT_MAXLENGTH];
	static char string[LEXER_STRING_MAXLENGTH];


	if(creg >= MAX_COMMENTINFO-1)
		yyerror("!commentinfo-buffer overflow");

	if (tmp != yylineno)
	{
		tmp = yylineno;
		//printf("Curren row:%d \n",yylineno);
	}
	if(creg == 0)
	{ //initial bound
		struct CommentInfo cib;
		cib.bound = 1;
		cib.lastline = 1;
		cib.lastcol = 1;
		commentInfo[creg++] = cib;
	}
	else if(yylineno == specboundline + 2 && columnno == 0)
	{ //bound after result
		spreg = creg;
		createBound(1);
	}

	val = (struct Token *) malloc(sizeof(struct Token));
	if (!val)
		yyerror("!out of memory");
	memset(val, 0, sizeof(struct Token));

	yylval = (rml_t) val;

	c = get();

#ifdef LEXER_TOKEN_POSITION
	val->file      = yyThisFileName;
	val->firstline = yylineno;
	val->firstcol  = columnno;
	val->lastline  = yylineno;
	val->lastcol   = columnno;
#endif

	switch (c)
	{
	case '\n': case ' ': case '\t':
		return yylex0();

	case EOF: case 0:
		return EOF;

	case '=': /* '=' or '=>' or == or ==. */
		d = get();
		if (d == '>')
		{ token = YIELDS; break; }
		if (d == '=')
		{
			e = get();
			if (e == '.') { token = EQEQ_REAL; break; }
			unget();
			token = EQEQ_INT; break;
		}
		unget();
		token = EQUALS;
		break;

	case '<': /* < or <= or <=. or <. or <> or <>. */
		d = get();
		if (d == '.') { token = LT_REAL; break; }
		if (d == '=')
		{
			e = get();
			if (e = '.') { token = LE_REAL; break; }
			unget();
			token = LE_INT; break;
		}
		if (d == '>')
		{
			e = get();
			if (e = '.') { token = NE_REAL; break; }
			unget();
			token = NE_INT; break;
		}
		unget();
		token = LT_INT;
		break;

	case '>': /* > or >= or >=. or >. */
		d = get();
		if (d == '.') { token = GT_REAL; break; }
		if (d == '=')
		{
			e = get();
			if (e = '.') { token = GE_REAL; break; }
			unget();
			token = GE_INT; break;
		}
		unget();
		token = GT_INT;
		break;

	case '!': /* != or !=. */
		d = get();
		if (d == '=')
		{
			e = get();
			if (e = '.') { token = NE_REAL; break; }
			unget();
			token = NE_INT; break;
		}
		yyerror("invalid comparison operator!");
		break;


	case ':': /* ':' or '::' */
		d = get();
		if (d == ':')
		{ token = COLONCOLON; break; }
		unget();
		token = COLON;
		break;

	case '(': /* '(' or '(*...comment...*)' */
		d = get();
		if (d == '*')
		{
			struct CommentInfo ci;//added
			ci.firstline = yylineno;//added
			ci.firstcol = columnno;
			yyCommentLength = 0; //added

			int innercomments = 1;

			while (d != EOF)
			{
				d = get();
				if (d != '*' && d != '(')
				{
					if (yyCommentLength < LEXER_COMMENT_MAXLENGTH)
						ci.buffer[yyCommentLength++] = d;
					continue;
				}
				if (d == '(')
				{
					d = get();
					if (d == '*')
					{
						if (yyCommentLength < LEXER_COMMENT_MAXLENGTH)
							ci.buffer[yyCommentLength++] = '(';
						if (yyCommentLength < LEXER_COMMENT_MAXLENGTH)
							ci.buffer[yyCommentLength++] = '*';
						innercomments++;
					}
					else
					{
						if (yyCommentLength < LEXER_COMMENT_MAXLENGTH)
							ci.buffer[yyCommentLength++] = '(';
					}
					unget();
				    continue;
				}
				if (d == '*')
				{
					d = get();
					if (d == ')')
					{
						if (yyCommentLength < LEXER_COMMENT_MAXLENGTH)
							ci.buffer[yyCommentLength++] = '*';
						if (yyCommentLength < LEXER_COMMENT_MAXLENGTH)
							ci.buffer[yyCommentLength++] = ')';
						innercomments--;
						if (innercomments == 0)
						{
							yyCommentLength--; /* don't put the last ')' */
							break;
						}
					}
					else
					{
						if (yyCommentLength < LEXER_COMMENT_MAXLENGTH)
							ci.buffer[yyCommentLength++] = '*';
					}
					unget();
					continue;
				}
			}
			ci.buffer[yyCommentLength] = 0;
			ci.lastline  = yylineno; //added
			ci.lastcol   = columnno; //added
			ci.bound = 0;
			commentInfo[creg++] = ci;//added
			return yylex0(); /* comment: skip and return next token */
		}
		unget();
		iinner = 1;
		token = LPAR;
		break;

	case '-': /* '-' or horizontal bar */
		d = get();
		if (d == '-')
		{
			while (d == '-')
				d = get();
			unget();
			createBound(1);
			specboundline = yylineno;
			token = DASHES;
			break;
		}
		unget();
		token = MINUS;
		break;

	case '"': /* string constant */
		i = 0;
		while (1)
		{
			c = get();
			if (c == '"')
				break;
			if (c == '\\')
				c = esc_char(0);
			if (i < LEXER_STRING_MAXLENGTH-1)
				string[i++] = c;
			else
				yyerror("string buffer overflow");
		}
		string[i] = 0;
		token = SCON;
		val->u.string = strdup(string);
		//printf("String: %s", val->u.string);
		break;

	case '#':
		c = get();
		if (c != '"')
			yyerror("invalid character constant");
		c = get();
		if (c == '\\')
			c = esc_char(1);
		d = get();
		if (d != '"')
			yyerror("invalid character constant");
		val->u.number = c;
		token = CCON;
		break;

	case ')':
		iinner = 0;
		token = RPAR;
		break;
	case '.':
		token = DOT;
		break;
	case ',':
		token = COMMA;
		break;
	case '/':
		token = DIV;
		break;
	case '+':
		token = PLUS;
		break;
	case '*':
		specboundline = yylineno; //can be problem if an expression...
		if(!iinner)
			createBound(3);
		token = STAR;
		break;

	case '|':
		token = BAR;
		createBound(1);
		specboundline = yylineno;
		break;

	case '&':
		token = AMPERSAND;
		createBound(1);
		break;
	case '[':
		token = LBRACK;
		break;
	case ']':
		token = RBRACK;
		break;
	case '%':
		token = MOD_INT;
		break;

	default:
		if (isalpha(c) || c == '\'' || c == '_')
		{
			i = 0;
			do
			{
				if (i < 50)
				{
					ident[i++] = c;
#ifdef LEXER_TOKEN_POSITION
					val->lastline = yylineno;
					val->lastcol  = columnno;
#endif
				}
				c = get();
			}
			while (isalnum(c) || c == '\'' || c == '_');

			unget();
			ident[i] = 0;

			if (!keywords_sorted)
			{
				init_sort_keywords();
				keywords_sorted = 1;
			}

			for(i = 0; keywords[i].name; ++i) {
				if (!strcmp(ident, keywords[i].name)) {
					if((keywords[i].code == KW_RELATION) || (keywords[i].code == KW_RULE) ||
						(keywords[i].code == KW_END) || (keywords[i].code == KW_MODULE) || (keywords[i].code == KW_TYPE)
						|| (keywords[i].code == KW_VAL) || (keywords[i].code == KW_WITH)) {
							if(keywords[i].code == KW_END) {
								if(spreg != 0) {
									commentInfo[spreg].bound = 2;
									spreg = 0;
								}
							}
							createBound(1);
						}
					else if((keywords[i].code == KW_AXIOM) || (keywords[i].code == KW_DATATYPE)
						|| (keywords[i].code == KW_AND)){
							createBound(1);
							specboundline = yylineno;

						}
						return keywords[i].code;
				}
			}
			val->u.ident = strdup(ident);
			//printf("the string: %s \n\n",ident);
			return ident[0] == '\'' ? TYVARIDENT : IDENT;
		}
		else if (isdigit(c))
		{
			int is_float = 0;

			i = 0;

			for(val->u.number = 0; isdigit(c); c = get())
			{
				val->u.number = val->u.number*10 + c-'0';
				if (i < LEXER_IDENT_MAXLENGTH)
					ident[i++] = c;
			};
			if (c == '.')
			{
				do
				{
					if (i < LEXER_IDENT_MAXLENGTH)
						ident[i++] = c;
					c = get();
				} while (isdigit(c));
				is_float = 1;
			};
			if (c == 'e')
			{
				do
				{
					if (i < LEXER_IDENT_MAXLENGTH)
						ident[i++] = c;
					c = get();
				} while (isdigit(c) || c == '+' || c == '-');
				is_float = 1;
			};

			unget();

			if (is_float)
			{
				ident[i] = 0;
				if (sscanf(ident, "%lf", &(val->u.realnumber)) == 1)
				{
					//printf("Real value %f",val->u.realnumber);
					token = RCON;
					break;
				}
				yyerror("invalid real number");
			}

			token = ICON;
			break;
		}
		else
			yyerror("invalid input character");
	}

#ifdef LEXER_TOKEN_POSITION
	val->lastline = yylineno;
	val->lastcol  = columnno;
#endif
	return token;
}
예제 #7
0
void ModelNode_KotOR::readMesh(Model_KotOR::ParserContext &ctx) {
	size_t P = ctx.mdl->pos();

	ctx.mdl->skip(8); // Function pointers

	uint32 facesOffset, facesCount;
	Model::readArrayDef(*ctx.mdl, facesOffset, facesCount);

	float boundingMin[3], boundingMax[3];

	boundingMin[0] = ctx.mdl->readIEEEFloatLE();
	boundingMin[1] = ctx.mdl->readIEEEFloatLE();
	boundingMin[2] = ctx.mdl->readIEEEFloatLE();

	boundingMax[0] = ctx.mdl->readIEEEFloatLE();
	boundingMax[1] = ctx.mdl->readIEEEFloatLE();
	boundingMax[2] = ctx.mdl->readIEEEFloatLE();

	float radius = ctx.mdl->readIEEEFloatLE();

	float pointsAverage[3];
	pointsAverage[0] = ctx.mdl->readIEEEFloatLE();
	pointsAverage[1] = ctx.mdl->readIEEEFloatLE();
	pointsAverage[2] = ctx.mdl->readIEEEFloatLE();

	_mesh = new Mesh();

	_mesh->diffuse[0] = ctx.mdl->readIEEEFloatLE();
	_mesh->diffuse[1] = ctx.mdl->readIEEEFloatLE();
	_mesh->diffuse[2] = ctx.mdl->readIEEEFloatLE();

	_mesh->ambient[0] = ctx.mdl->readIEEEFloatLE();
	_mesh->ambient[1] = ctx.mdl->readIEEEFloatLE();
	_mesh->ambient[2] = ctx.mdl->readIEEEFloatLE();

	_mesh->specular[0] = 0;
	_mesh->specular[1] = 0;
	_mesh->specular[2] = 0;

	uint32 transparencyHint = ctx.mdl->readUint32LE();

	_mesh->hasTransparencyHint = true;
	_mesh->transparencyHint    = (transparencyHint != 0);

	std::vector<Common::UString> textures;

	textures.push_back(Common::readStringFixed(*ctx.mdl, Common::kEncodingASCII, 32));
	textures.push_back(Common::readStringFixed(*ctx.mdl, Common::kEncodingASCII, 32));

	ctx.mdl->skip(24); // Unknown

	ctx.mdl->skip(12); // Vertex indices counts

	uint32 offOffVerts, offOffVertsCount;
	Model::readArrayDef(*ctx.mdl, offOffVerts, offOffVertsCount);

	if (offOffVertsCount > 1)
		throw Common::Exception("Face offsets offsets count wrong (%d)", offOffVertsCount);

	ctx.mdl->skip(12); // Unknown

	ctx.mdl->skip(24 + 16); // Unknown

	uint32 mdxStructSize = ctx.mdl->readUint32LE();

	ctx.mdl->skip(8); // Unknown

	uint32 offNormals = ctx.mdl->readUint32LE();

	ctx.mdl->skip(4); // Unknown

	uint32 offUV[2];
	offUV[0] = ctx.mdl->readUint32LE();
	offUV[1] = ctx.mdl->readUint32LE();

	ctx.mdl->skip(24); // Unknown

	uint16 vertexCount  = ctx.mdl->readUint16LE();
	uint16 textureCount = ctx.mdl->readUint16LE();

	ctx.mdl->skip(2);

	byte unknownFlag1 = ctx.mdl->readByte();
	_mesh->shadow  = ctx.mdl->readByte() == 1;
	byte unknownFlag2 = ctx.mdl->readByte();
	_mesh->render  = ctx.mdl->readByte() == 1;

	ctx.mdl->skip(10);

	if (ctx.kotor2)
		ctx.mdl->skip(8);

	uint32 offNodeData = ctx.mdl->readUint32LE();

	ctx.mdl->skip(4);

	if ((offOffVertsCount < 1) || (vertexCount == 0) || (facesCount == 0))
		return;

	_render = _mesh->render;
	_mesh->data = new MeshData();
	_mesh->data->envMapMode = kModeEnvironmentBlendedOver;

	uint32 endPos = ctx.mdl->pos();

	if (textureCount > 2) {
		warning("Model_KotOR::readMesh(): textureCount > 2 (%d)", textureCount);
		textureCount = 2;
	}

	if ((textureCount > 0) && !ctx.texture.empty())
		textures[0] = ctx.texture;

	textures.resize(textureCount);
	loadTextures(textures);


	// Read vertices (interleaved)

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	for (uint t = 0; t < textureCount; t++)
		vertexDecl.push_back(VertexAttrib(VTCOORD + t , 2, GL_FLOAT));

	_mesh->data->vertexBuffer.setVertexDeclInterleave(vertexCount, vertexDecl);

	float *v = reinterpret_cast<float *>(_mesh->data->vertexBuffer.getData());
	for (uint32 i = 0; i < vertexCount; i++) {
		// Position
		ctx.mdx->seek(offNodeData + i * mdxStructSize);
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();

		// Normal
		//ctx.mdx->seek(offNodeData + i * mdxStructSize + offNormals);
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();
		*v++ = ctx.mdx->readIEEEFloatLE();

		// TexCoords
		for (uint16 t = 0; t < textureCount; t++) {
			if (offUV[t] != 0xFFFFFFFF) {
				ctx.mdx->seek(offNodeData + i * mdxStructSize + offUV[t]);
				*v++ = ctx.mdx->readIEEEFloatLE();
				*v++ = ctx.mdx->readIEEEFloatLE();
			} else {
				*v++ = 0.0f;
				*v++ = 0.0f;
			}
		}
	}


	// Read faces

	ctx.mdl->seek(ctx.offModelData + offOffVerts);
	uint32 offVerts = ctx.mdl->readUint32LE();

	ctx.mdl->seek(ctx.offModelData + offVerts);

	_mesh->data->indexBuffer.setSize(facesCount * 3, sizeof(uint16), GL_UNSIGNED_SHORT);

	uint16 *f = reinterpret_cast<uint16 *>(_mesh->data->indexBuffer.getData());
	for (uint32 i = 0; i < facesCount * 3; i++)
		f[i] = ctx.mdl->readUint16LE();

	createBound();

	ctx.mdl->seek(endPos);
}
예제 #8
0
파일: model_nwn2.cpp 프로젝트: Glyth/xoreos
bool ModelNode_NWN2::loadSkin(Model_NWN2::ParserContext &ctx) {
	uint32 tag = ctx.mdb->readUint32BE();
	if (tag != kSkinID)
		throw Common::Exception("Invalid skin packet signature (%s)", Common::debugTag(tag).c_str());

	uint32 packetSize = ctx.mdb->readUint32LE();

	_name = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

	// Skipping lower level of detail models
	if (_name.endsWith("_L01") || _name.endsWith("_L02"))
		return false;

	Common::UString skeletonName = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

	Common::UString diffuseMap = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);
	Common::UString normalMap  = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);
	                _tintMap   = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);
	Common::UString glowMap    = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

	_diffuse [0] = ctx.mdb->readIEEEFloatLE();
	_diffuse [1] = ctx.mdb->readIEEEFloatLE();
	_diffuse [2] = ctx.mdb->readIEEEFloatLE();
	_specular[0] = ctx.mdb->readIEEEFloatLE();
	_specular[1] = ctx.mdb->readIEEEFloatLE();
	_specular[2] = ctx.mdb->readIEEEFloatLE();

	float  specularPower = ctx.mdb->readIEEEFloatLE();
	float  specularValue = ctx.mdb->readIEEEFloatLE();
	uint32 textureFlags  = ctx.mdb->readUint32LE();

	uint32 vertexCount = ctx.mdb->readUint32LE();
	uint32 facesCount  = ctx.mdb->readUint32LE();

	if ((vertexCount == 0) || (facesCount == 0))
		return false;

	std::vector<Common::UString> textures;
	textures.push_back(diffuseMap);

	loadTextures(textures);

	// Read vertices (interleaved)

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VTCOORD  , 3, GL_FLOAT));

	if (!_tintMap.empty())
		vertexDecl.push_back(VertexAttrib(VTCOORD + 1, 3, GL_FLOAT));

	_vertexBuffer.setVertexDeclInterleave(vertexCount, vertexDecl);

	float *v = (float *) _vertexBuffer.getData();
	for (uint32 i = 0; i < vertexCount; i++) {
		// Position
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();

		// Normal
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();

		ctx.mdb->skip(4 * 4); // Bone weights
		ctx.mdb->skip(4 * 1); // Bone indices
		ctx.mdb->skip(3 * 4); // Tangent
		ctx.mdb->skip(3 * 4); // Binormal

		// TexCoords
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();

		// TintMap TexCoords
		if (!_tintMap.empty()) {
			v[0] = v[-3];
			v[1] = v[-2];
			v[2] = v[-1];
			v += 3;
		}

		ctx.mdb->skip(4); // Bone count
	}


	// Read faces

	_indexBuffer.setSize(facesCount * 3, sizeof(uint16), GL_UNSIGNED_SHORT);

	uint16 *f = (uint16 *) _indexBuffer.getData();
	for (uint32 i = 0; i < facesCount * 3; i++)
		f[i] = ctx.mdb->readUint16LE();

	createBound();

	_render = true;

	return true;
}