Esempio n. 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);
}
Esempio n. 2
0
void loadNiKeyframeController(Niflib::NiKeyframeControllerRef obj, RefMap& refmap)
{
	//make a new animation controller
	KeyframeAnimationObject *result = new KeyframeAnimationObject();

	//load data
	result->length = obj->GetStopTime();

	Niflib::NiKeyframeDataRef data = Niflib::DynamicCast<Niflib::NiKeyframeData>(obj->GetData());

	for (Niflib::Key<Niflib::Vector3> key: data->GetTranslateKeys()) {
		result->positionKeys.addKey(key.time, NifToGlmVec3(key.data));
	}

	for (Niflib::Key<Niflib::Quaternion> key: data->GetQuatRotateKeys()) {
		result->rotationKeys.addKey(key.time, NifToGlmQuat(key.data));
	}

	for (Niflib::Key<float> key: data->GetScaleKeys()) {
		result->scaleKeys.addKey(key.time, glm::vec3(key.data, key.data, key.data));
	}

	result->setTarget(refmap.getNode(obj->GetTarget()));
	
	refmap.currentModel->addController(result);
}
Esempio n. 3
0
void loadNiSkinInstance(SkinnedMesh *mesh, Niflib::NiSkinInstanceRef skin, RefMap& refmap)
{
	Niflib::NiSkinDataRef skindata = skin->GetSkinData();

	for (unsigned int ibone=0; ibone<skin->GetBoneCount(); ibone++) {
		mesh->bones.push_back(refmap.getNode(skin->GetBones()[ibone]));

		Niflib::Matrix44 offset = skindata->GetBoneTransform(ibone);
		mesh->boneOffsets.push_back(NifToGlmMat4(offset));

		for (Niflib::SkinWeight weight: skindata->GetBoneWeights(ibone)) {
			mesh->vertices->get(weight.index).addBone(ibone, weight.weight);
		}
	}

	mesh->root = refmap.getNode(skin->GetSkeletonRoot());
}
Esempio n. 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);
}