Пример #1
0
void loadNiTriShapeData(Niflib::NiTriShapeRef parent, Niflib::NiTriShapeDataRef data, 
								RefMap& refmap) {
	Renderable *result;

	if (parent->GetSkinInstance()) {
		SkinnedMesh *mesh = new SkinnedMesh(true);

		loadNiTriShapeVertices(mesh, data);
		loadNiTriShapeMaterial(mesh, parent);
		loadNiSkinInstance(mesh, parent->GetSkinInstance(), refmap);
		mesh->parent = refmap.getNode(parent);

		result = mesh;
	}
	else {
		Mesh *mesh = new Mesh(true);

		loadNiTriShapeVertices(mesh, data);
		loadNiTriShapeMaterial(mesh, parent);
		mesh->parent = refmap.getNode(parent);

		result = mesh;
	}

	refmap.currentModel->addRenderable(result);
}
Пример #2
0
void generateCollisionShape(std::vector<Niflib::NiObjectRef>& objs, RefMap& refmap)
{
	btCompoundShape *shape = new btCompoundShape();

	for (auto& obj: objs) {
		if (obj->GetType().IsSameType(Niflib::NiTriShape::TYPE)) {
			Niflib::NiTriShapeRef trishape = Niflib::DynamicCast<Niflib::NiTriShape>(obj);
			if (trishape->GetCollisionMode() == Niflib::NiAVObject::CT_TRIANGLES) {
				btCollisionShape *subshape = loadCollisionHull(trishape);
				shape->addChildShape(getBtNodeTransform(trishape), subshape);
			}
			else if (trishape->GetCollisionMode() == Niflib::NiAVObject::CT_BOUNDINGBOX) {
				btCollisionShape *subshape = loadCollisionBox(trishape);
				shape->addChildShape(getBtNodeTransform(trishape), subshape);
			}
		}
	}

	refmap.currentModel->setShape(shape);
}
Пример #3
0
void loadNiTriShapeMaterial(T *mesh, Niflib::NiTriShapeRef data)
{
	//load texture
	Niflib::NiTexturingPropertyRef tex = Niflib::DynamicCast<Niflib::NiTexturingProperty>(
					data->GetPropertyByType(Niflib::NiTexturingProperty::TYPE));
	if (tex) {
		std::string img = tex->GetTexture(0).source->GetTextureFileName();
		mesh->material.shader = Shader::get(Shader::Key(SHADER_FRAGMENT, "textured.frag"));
		mesh->material.diffuseTexture = Texture::get(img);
	}
}
Пример #4
0
void loadNiNode(Niflib::NiAVObjectRef node, RefMap& refmap) {
	//make a new node
	Node *result = refmap.getNode(node);

	//load data
	result->setName(node->GetName());
	result->setPosition(NifToGlmVec3(node->GetLocalTranslation()));
	result->setRotation(NifToGlmQuat(node->GetLocalRotation().AsQuaternion()));
	result->setScale(glm::vec3(node->GetLocalScale(),node->GetLocalScale(),node->GetLocalScale()));

	for (Niflib::NiExtraDataRef& extradata: node->GetExtraData()) {
		if (extradata->GetType().IsSameType(Niflib::NiStringExtraData::TYPE)) {
			Niflib::NiStringExtraDataRef strdata = Niflib::DynamicCast<Niflib::NiStringExtraData>(
														extradata);
			if (strdata->GetData() == "NCO") {
				refmap.hasCollision = false;
			}
		}
	}

	if (node->GetType().IsSameType(Niflib::NiTriShape::TYPE)) {
		Niflib::NiTriShapeRef temp = Niflib::DynamicCast<Niflib::NiTriShape>(node);
		Niflib::NiTriShapeDataRef tempdata = Niflib::DynamicCast<Niflib::NiTriShapeData>(temp->GetData());
		loadNiTriShapeData(temp, tempdata, refmap);
	}
	else if (node->GetType().IsSameType(Niflib::RootCollisionNode::TYPE)) {
		refmap.collisionnode = Niflib::DynamicCast<Niflib::RootCollisionNode>(node);
	}

	result->isVisible = node->GetVisibility();

	//attach this node to its parent
	Niflib::NiNodeRef parent = node->GetParent();
	if (parent) {
		Node *parnode = refmap.getNode(parent);
		parnode->addChild(result);
	}

	refmap.currentModel->addNamedNode(node->GetName(), result);
}
Пример #5
0
void openglwindow::getfilen(const char* fname)
{

	Niflib::NiObjectRef niparentobject;
		niparentobject=Niflib::ReadNifTree(fname);
		Niflib::NiNodeRef niparentnode;
        niparentnode=Niflib::DynamicCast<Niflib::NiNode>(niparentobject);
		vector<Niflib::NiAVObjectRef> niavparent=niparentnode->GetChildren();
		const aiMesh* m;
		for(int i=0 ; i< niavparent.size();i++)
		{
			if (niavparent[i]->GetType().GetTypeName()=="NiTriShape")
            {
				shape=Niflib::DynamicCast<Niflib::NiTriShape>(niavparent[i]);
				ndata= Niflib::DynamicCast<Niflib::NiTriBasedGeomData>(shape->GetData());
				gl::GLWriter wr;
				
		    }
		}
}