Beispiel #1
0
void drawVector(RenderingContext & rc, const Geometry::Vec3 & from, const Geometry::Vec3 & to) {
	static Util::Reference<Mesh> mesh;
	if (mesh.isNull()) {
		VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		mesh = new Mesh(vertexDescription, 2, 2);
		mesh->setDrawMode(Mesh::DRAW_LINES);

		MeshIndexData & id = mesh->openIndexData();
		uint32_t * indices = id.data();
		indices[0] = 0;
		indices[1] = 1;
		id.updateIndexRange();
		id.markAsChanged();
		mesh->setDataStrategy(SimpleMeshDataStrategy::getPureLocalStrategy());
	}

	MeshVertexData & vd = mesh->openVertexData();
	float * vertices = reinterpret_cast<float *> (vd.data());
	*vertices++ = from.getX(); // From
	*vertices++ = from.getY();
	*vertices++ = from.getZ();
	*vertices++ = to.getX(); // To
	*vertices++ = to.getY();
	*vertices++ = to.getZ();
	vd.updateBoundingBox();
	vd.markAsChanged();

	rc.displayMesh(mesh.get());
}
Beispiel #2
0
static void describeGeometryNode(ExporterContext & /*ctxt*/,DescriptionMap & desc, Node * node) {
	desc.setString(Consts::ATTR_NODE_TYPE, Consts::NODE_TYPE_GEOMETRY);

	std::unique_ptr<DescriptionMap> dataDesc(new DescriptionMap);

	GeometryNode * gn = dynamic_cast<GeometryNode*>(node);

	// annotate with bounding box
	const Geometry::Box bb = gn->getBB();
	const Geometry::Vec3 center = bb.getCenter();
	std::stringstream s;
	s << center.getX() << " " << center.getY() << " " << center.getZ() << " " << bb.getExtentX() << " " << bb.getExtentY() << " " << bb.getExtentZ();
	dataDesc->setString(Consts::ATTR_MESH_BB, s.str());

	Rendering::Mesh * m = gn->getMesh();
	if(m!=nullptr) { // mesh present?
		// no filename -> store data in .minsg
		if(m->getFileName().empty()) {
			std::ostringstream meshStream;
			if(Rendering::Serialization::saveMesh(gn->getMesh(), "mmf", meshStream)) {
				dataDesc->setString(Consts::ATTR_DATA_TYPE,"mesh");
				dataDesc->setString(Consts::ATTR_DATA_ENCODING,"base64");
				const std::string streamString = meshStream.str();
				const std::string meshString = Util::encodeBase64(std::vector<uint8_t>(streamString.begin(), streamString.end()));
				dataDesc->setString(Consts::DATA_BLOCK,meshString);
			}
		} else { // filename given?
			Util::FileName meshFilename(m->getFileName());

//			// make path to mesh relative to scene (if mesh lies below the scene)
//			Util::FileUtils::makeRelativeIfPossible(ctxt.sceneFile, meshFilename);

			dataDesc->setString(Consts::ATTR_DATA_TYPE,"mesh");
			dataDesc->setString(Consts::ATTR_MESH_FILENAME,meshFilename.toShortString());
		}
		ExporterTools::addDataEntry(desc, std::move(dataDesc));
	}

}
Beispiel #3
0
void drawQuad(RenderingContext & rc, const Geometry::Vec3 & lowerLeft, const Geometry::Vec3 & lowerRight, const Geometry::Vec3 & upperRight,
				const Geometry::Vec3 & upperLeft) {
	static Util::Reference<Mesh> mesh;
	if (mesh.isNull()) {
		VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		vertexDescription.appendNormalFloat();
		vertexDescription.appendTexCoord();
		mesh = new Mesh(vertexDescription, 4, 6);

		MeshIndexData & id = mesh->openIndexData();
		uint32_t * indices = id.data();
		indices[0] = 0;
		indices[1] = 1;
		indices[2] = 2;
		indices[3] = 0;
		indices[4] = 2;
		indices[5] = 3;
		id.updateIndexRange();
		id.markAsChanged();
	}
	const Geometry::Vec3 edgeA = lowerRight - lowerLeft;
	const Geometry::Vec3 edgeB = upperLeft - lowerLeft;
	Geometry::Vec3 normal = edgeA.cross(edgeB);
	normal.normalize();

	MeshVertexData & vd = mesh->openVertexData();
	float * vertices = reinterpret_cast<float *> (vd.data());
	// Lower left
	*vertices++ = lowerLeft.getX();
	*vertices++ = lowerLeft.getY();
	*vertices++ = lowerLeft.getZ();
	*vertices++ = normal.getX();
	*vertices++ = normal.getY();
	*vertices++ = normal.getZ();
	*vertices++ = 0.0f;
	*vertices++ = 0.0f;
	// Lower right
	*vertices++ = lowerRight.getX();
	*vertices++ = lowerRight.getY();
	*vertices++ = lowerRight.getZ();
	*vertices++ = normal.getX();
	*vertices++ = normal.getY();
	*vertices++ = normal.getZ();
	*vertices++ = 1.0f;
	*vertices++ = 0.0f;
	// Upper right
	*vertices++ = upperRight.getX();
	*vertices++ = upperRight.getY();
	*vertices++ = upperRight.getZ();
	*vertices++ = normal.getX();
	*vertices++ = normal.getY();
	*vertices++ = normal.getZ();
	*vertices++ = 1.0f;
	*vertices++ = 1.0f;
	// Upper left
	*vertices++ = upperLeft.getX();
	*vertices++ = upperLeft.getY();
	*vertices++ = upperLeft.getZ();
	*vertices++ = normal.getX();
	*vertices++ = normal.getY();
	*vertices++ = normal.getZ();
	*vertices++ = 0.0f;
	*vertices++ = 1.0f;
	vd.updateBoundingBox();
	vd.markAsChanged();

	rc.displayMesh(mesh.get());
}