コード例 #1
0
ファイル: wieldmesh.cpp プロジェクト: Gael-de-Sailly/minetest
void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
{
	ITextureSource *tsrc = client->getTextureSource();
	IItemDefManager *idef = client->getItemDefManager();
	const NodeDefManager *ndef = client->getNodeDefManager();
	const ItemDefinition &def = item.getDefinition(idef);
	const ContentFeatures &f = ndef->get(def.name);
	content_t id = ndef->getId(def.name);

	FATAL_ERROR_IF(!g_extrusion_mesh_cache, "Extrusion mesh cache is not yet initialized");
	
	scene::SMesh *mesh = nullptr;

	// Shading is on by default
	result->needs_shading = true;

	// If inventory_image is defined, it overrides everything else
	if (!def.inventory_image.empty()) {
		mesh = getExtrudedMesh(tsrc, def.inventory_image,
			def.inventory_overlay);
		result->buffer_colors.emplace_back();
		// overlay is white, if present
		result->buffer_colors.emplace_back(true, video::SColor(0xFFFFFFFF));
		// Items with inventory images do not need shading
		result->needs_shading = false;
	} else if (def.type == ITEM_NODE) {
		if (f.mesh_ptr[0]) {
			mesh = cloneMesh(f.mesh_ptr[0]);
			scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
			postProcessNodeMesh(mesh, f, false, false, nullptr,
				&result->buffer_colors);
		} else {
			switch (f.drawtype) {
				case NDT_PLANTLIKE: {
					mesh = getExtrudedMesh(tsrc,
						tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
						tsrc->getTextureName(f.tiles[0].layers[1].texture_id));
					// Add color
					const TileLayer &l0 = f.tiles[0].layers[0];
					result->buffer_colors.emplace_back(l0.has_color, l0.color);
					const TileLayer &l1 = f.tiles[0].layers[1];
					result->buffer_colors.emplace_back(l1.has_color, l1.color);
					break;
				}
				case NDT_PLANTLIKE_ROOTED: {
					mesh = getExtrudedMesh(tsrc,
						tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), "");
					// Add color
					const TileLayer &l0 = f.special_tiles[0].layers[0];
					result->buffer_colors.emplace_back(l0.has_color, l0.color);
					break;
				}
				case NDT_NORMAL:
				case NDT_ALLFACES:
				case NDT_LIQUID:
				case NDT_FLOWINGLIQUID: {
					scene::IMesh *cube = g_extrusion_mesh_cache->createCube();
					mesh = cloneMesh(cube);
					cube->drop();
					scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
					// add overlays
					postProcessNodeMesh(mesh, f, false, false, nullptr,
						&result->buffer_colors);
					break;
				}
				default: {
					mesh = createSpecialNodeMesh(client, id, &result->buffer_colors);
					scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
				}
			}
		}

		u32 mc = mesh->getMeshBufferCount();
		for (u32 i = 0; i < mc; ++i) {
			scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
			video::SMaterial &material = buf->getMaterial();
			material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
			material.setFlag(video::EMF_BILINEAR_FILTER, false);
			material.setFlag(video::EMF_TRILINEAR_FILTER, false);
			material.setFlag(video::EMF_BACK_FACE_CULLING, true);
			material.setFlag(video::EMF_LIGHTING, false);
		}

		rotateMeshXZby(mesh, -45);
		rotateMeshYZby(mesh, -30);
	}
	result->mesh = mesh;
}
コード例 #2
0
ファイル: wieldmesh.cpp プロジェクト: DomtronVox/minetest
scene::IMesh *getItemMesh(Client *client, const ItemStack &item)
{
	ITextureSource *tsrc = client->getTextureSource();
	IItemDefManager *idef = client->getItemDefManager();
	INodeDefManager *ndef = client->getNodeDefManager();
	const ItemDefinition &def = item.getDefinition(idef);
	const ContentFeatures &f = ndef->get(def.name);
	content_t id = ndef->getId(def.name);

	if (!g_extrusion_mesh_cache) {
		g_extrusion_mesh_cache = new ExtrusionMeshCache();
	} else {
		g_extrusion_mesh_cache->grab();
	}

	scene::IMesh *mesh;

	// If inventory_image is defined, it overrides everything else
	if (def.inventory_image != "") {
		mesh = getExtrudedMesh(tsrc, def.inventory_image);
		return mesh;
	} else if (def.type == ITEM_NODE) {
		if (f.mesh_ptr[0]) {
			mesh = cloneMesh(f.mesh_ptr[0]);
			scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
			setMeshColor(mesh, video::SColor (255, 255, 255, 255));
		} else if (f.drawtype == NDT_PLANTLIKE) {
			mesh = getExtrudedMesh(tsrc,
				tsrc->getTextureName(f.tiles[0].texture_id));
		} else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES
			|| f.drawtype == NDT_LIQUID || f.drawtype == NDT_FLOWINGLIQUID) {
			mesh = cloneMesh(g_extrusion_mesh_cache->createCube());
			scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
		} else {
			MeshMakeData mesh_make_data(client, false);
			MapNode mesh_make_node(id, 255, 0);
			mesh_make_data.fillSingleNode(&mesh_make_node);
			MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
			mesh = cloneMesh(mapblock_mesh.getMesh());
			translateMesh(mesh, v3f(-BS, -BS, -BS));
			scaleMesh(mesh, v3f(0.12, 0.12, 0.12));

			u32 mc = mesh->getMeshBufferCount();
			for (u32 i = 0; i < mc; ++i) {
				video::SMaterial &material1 =
					mesh->getMeshBuffer(i)->getMaterial();
				video::SMaterial &material2 =
					mapblock_mesh.getMesh()->getMeshBuffer(i)->getMaterial();
				material1.setTexture(0, material2.getTexture(0));
				material1.setTexture(1, material2.getTexture(1));
				material1.setTexture(2, material2.getTexture(2));
				material1.setTexture(3, material2.getTexture(3));
				material1.MaterialType = material2.MaterialType;
			}
		}

		u32 mc = mesh->getMeshBufferCount();
		for (u32 i = 0; i < mc; ++i) {
			const TileSpec *tile = &(f.tiles[i]);
			scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
			colorizeMeshBuffer(buf, &tile->color);
			video::SMaterial &material = buf->getMaterial();
			material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
			material.setFlag(video::EMF_BILINEAR_FILTER, false);
			material.setFlag(video::EMF_TRILINEAR_FILTER, false);
			material.setFlag(video::EMF_BACK_FACE_CULLING, true);
			material.setFlag(video::EMF_LIGHTING, false);
			if (tile->animation_frame_count > 1) {
				FrameSpec animation_frame = tile->frames[0];
				material.setTexture(0, animation_frame.texture);
			} else {
				material.setTexture(0, tile->texture);
			}
		}

		rotateMeshXZby(mesh, -45);
		rotateMeshYZby(mesh, -30);
		return mesh;
	}
	return NULL;
}