Exemple #1
0
void EERIE_Object_Precompute_Fast_Access(EERIE_3DOBJ * eerie) {
	
	if(!eerie)
		return;

	// GetActionPointIdx(eerie, "v_right");
	// GetActionPointIdx(eerie, "u_right");
	// GetActionPointIdx(eerie, "carry_attach");
	// EERIE_OBJECT_GetGroup(eerie, "jaw");
	// EERIE_OBJECT_GetGroup(eerie, "mouth all");
	
	eerie->fastaccess.view_attach       = GetActionPointIdx(eerie, "view_attach");
	eerie->fastaccess.primary_attach    = GetActionPointIdx(eerie, "primary_attach");
	eerie->fastaccess.left_attach       = GetActionPointIdx(eerie, "left_attach");
	eerie->fastaccess.weapon_attach     = GetActionPointIdx(eerie, "weapon_attach");
	eerie->fastaccess.secondary_attach  = GetActionPointIdx(eerie, "secondary_attach");
	eerie->fastaccess.fire              = GetActionPointIdx(eerie, "fire");
	
	eerie->fastaccess.head_group = EERIE_OBJECT_GetGroup(eerie, "head");

	if(eerie->fastaccess.head_group == -1)
		eerie->fastaccess.head_group_origin = -1;
	else
	{
		long lHeadOrigin  = eerie->grouplist[eerie->fastaccess.head_group].origin;
		eerie->fastaccess.head_group_origin = checked_range_cast<short>(lHeadOrigin);
	}
	
	eerie->fastaccess.sel_head     = EERIE_OBJECT_GetSelection(eerie, "head");
	eerie->fastaccess.sel_chest    = EERIE_OBJECT_GetSelection(eerie, "chest");
	eerie->fastaccess.sel_leggings = EERIE_OBJECT_GetSelection(eerie, "leggings");
}
Exemple #2
0
void EERIE_Object_Precompute_Fast_Access(EERIE_3DOBJ * eerie) {
	
	if(!eerie)
		return;

	// GetActionPointIdx(eerie, "v_right");
	// GetActionPointIdx(eerie, "u_right");
	// GetActionPointIdx(eerie, "carry_attach");
	// EERIE_OBJECT_GetGroup(eerie, "jaw");
	// EERIE_OBJECT_GetGroup(eerie, "mouth all");
	
	eerie->fastaccess.view_attach       = GetActionPointIdx(eerie, "view_attach");
	eerie->fastaccess.primary_attach    = GetActionPointIdx(eerie, "primary_attach");
	eerie->fastaccess.left_attach       = GetActionPointIdx(eerie, "left_attach");
	eerie->fastaccess.weapon_attach     = GetActionPointIdx(eerie, "weapon_attach");
	eerie->fastaccess.secondary_attach  = GetActionPointIdx(eerie, "secondary_attach");
	eerie->fastaccess.fire              = GetActionPointIdx(eerie, "fire");
	
	eerie->fastaccess.head_group = EERIE_OBJECT_GetGroup(eerie, "head");

	if(eerie->fastaccess.head_group != ObjVertGroup()) {
		ObjVertHandle lHeadOrigin = ObjVertHandle(eerie->grouplist[eerie->fastaccess.head_group.handleData()].origin);
		eerie->fastaccess.head_group_origin = lHeadOrigin;
	}
	
	eerie->fastaccess.sel_head     = EERIE_OBJECT_GetSelection(eerie, "head");
	eerie->fastaccess.sel_chest    = EERIE_OBJECT_GetSelection(eerie, "chest");
	eerie->fastaccess.sel_leggings = EERIE_OBJECT_GetSelection(eerie, "leggings");
}
Exemple #3
0
// Converts a Theo Object to an EERIE object
static EERIE_3DOBJ * TheoToEerie(const char * adr, long size, const res::path & texpath, const res::path & fic) {
	
	LogWarning << "TheoToEerie " << fic;
	
	if(!adr)
		return NULL;
	
	res::path txpath = texpath.empty() ? "graph/obj3d/textures" : texpath;
	
	if(size < 10) {
		return NULL;
	}
	
	size_t pos = 0;
	
	const THEO_HEADER * pth = reinterpret_cast<const THEO_HEADER *>(adr + pos);
	pos += sizeof(THEO_HEADER);
	
	if(pth->version < 3003 || pth->version > 3011) {
		LogError << "TheoToEerie: invalid version in " << fic << ": found " << pth->version
		         << " expected 3004 to 3011";
		return NULL;
	}
	
	EERIE_3DOBJ * eerie = new EERIE_3DOBJ;
	eerie->clear();
	
	eerie->file = fic;
	
	if(pth->type_write == 0) {
		// read the texture
		
		LogError <<  "WARNING object " << fic << " SAVE MAP IN OBJECT = INVALID... Using Dummy Textures...";
		
		eerie->texturecontainer.resize(pth->nb_maps);
		for(long i = 0; i < pth->nb_maps; i++) {
			pos += sizeof(THEO_TEXTURE);
			eerie->texturecontainer[i] = GetAnyTexture();
		}
		
	} else {
		
		if((pth->type_write & SAVE_MAP_BMP) || (pth->type_write & SAVE_MAP_TGA)) {
			
			eerie->texturecontainer.resize(pth->nb_maps);
			for(long i = 0; i < pth->nb_maps; i++) {
				
				res::path name;
				if(pth->version >= 3008) {
					const THEO_SAVE_MAPS_IN_3019 * tsmi3019 = reinterpret_cast<const THEO_SAVE_MAPS_IN_3019 *>(adr + pos);
					pos += sizeof(THEO_SAVE_MAPS_IN_3019);
					name = res::path::load(util::loadString(tsmi3019->texture_name)).remove_ext();
				} else {
					const THEO_SAVE_MAPS_IN * tsmi = reinterpret_cast<const THEO_SAVE_MAPS_IN *>(adr + pos);
					pos += sizeof(THEO_SAVE_MAPS_IN);
					name = res::path::load(util::loadString(tsmi->texture_name)).remove_ext();
				}
				
				if(!name.empty()) {
					eerie->texturecontainer[i] = TextureContainer::Load(txpath / name, TextureContainer::Level);
				}
			}
		}
	}
	
	pos = pth->object_seek;
	loadObjectData(eerie, adr, &pos, pth->version);
	eerie->angle = Anglef::ZERO;
	eerie->pos = Vec3f_ZERO;

	// NORMALS CALCULATIONS

	//Compute Faces Areas
	for(size_t i = 0; i < eerie->facelist.size(); i++) {
		const Vec3f & p0 = eerie->vertexlist[eerie->facelist[i].vid[0]].v;
		const Vec3f & p1 = eerie->vertexlist[eerie->facelist[i].vid[1]].v;
		const Vec3f & p2 = eerie->vertexlist[eerie->facelist[i].vid[2]].v;
		eerie->facelist[i].temp = glm::distance((p0 + p1) * .5f, p2) * glm::distance(p0, p1) * .5f;
	}

	for(size_t i = 0; i < eerie->facelist.size(); i++) {
		CalcObjFaceNormal(
		    &eerie->vertexlist[eerie->facelist[i].vid[0]].v,
		    &eerie->vertexlist[eerie->facelist[i].vid[1]].v,
		    &eerie->vertexlist[eerie->facelist[i].vid[2]].v,
		    &eerie->facelist[i]
		);
		float area = eerie->facelist[i].temp;

		for(long j = 0; j < 3; j++) {
			float mod = area * area;
			Vec3f nrml = eerie->facelist[i].norm * mod;
			float count = mod;

			for(size_t i2 = 0; i2 < eerie->facelist.size(); i2++) {
				if(i != i2) {
					float area2 = eerie->facelist[i].temp;

					for(long j2 = 0; j2 < 3; j2++) {
						if(closerThan(eerie->vertexlist[eerie->facelist[i2].vid[j2]].v, eerie->vertexlist[eerie->facelist[i].vid[j]].v, .1f)) {
							mod = (area2 * area2);
							nrml += eerie->facelist[i2].norm * mod;
							count += mod; 
						}
					}
				}
			}

			count = 1.f / count;
			eerie->vertexlist[eerie->facelist[i].vid[j]].vert.p = nrml * count;
		}
	}

	for(size_t i = 0; i < eerie->facelist.size(); i++) {
		for(long j = 0; j < 3; j++) {
			eerie->vertexlist[eerie->facelist[i].vid[j]].norm = eerie->vertexlist[eerie->facelist[i].vid[j]].vert.p;
		}
	}

	// Apply Normals Spherical correction for NPC head
	long neck_orgn = GetGroupOriginByName(eerie, "neck");
	long head_idx = EERIE_OBJECT_GetGroup(eerie, "head");

	if(head_idx >= 0 && neck_orgn >= 0) {
		VertexGroup & headGroup = eerie->grouplist[head_idx];
		
		Vec3f center = Vec3f_ZERO;
		Vec3f origin = eerie->vertexlist[neck_orgn].v;
		float count = (float)headGroup.indexes.size();

		if(count > 0.f) {
			for(size_t idx = 0 ; idx < headGroup.indexes.size(); idx++) {
				center += eerie->vertexlist[ headGroup.indexes[idx] ].v;
			}
			
			center = (center * (1.f / count) + origin + origin) * (1.0f / 3);
			float max_threshold = glm::distance(origin, center);
			
			for(size_t i = 0; i < headGroup.indexes.size(); i++) {
				EERIE_VERTEX * ev = &eerie->vertexlist[headGroup.indexes[i]];
				float d = glm::distance(ev->v, origin);
				float factor = 1.f;

				if(d < max_threshold) {
					factor = d / max_threshold;
				}

				float ifactor = 1.f - factor;
				Vec3f fakenorm;
				fakenorm = ev->v - center;
				fakenorm = glm::normalize(fakenorm);
				ev->norm = ev->norm * ifactor + fakenorm * factor;
				ev->norm = glm::normalize(ev->norm);
			}
		}
	}

	// NORMALS CALCULATIONS END
	//***********************************************************
	
	eerie->m_skeleton = NULL;
	EERIE_CreateCedricData(eerie);
	return eerie;
}