示例#1
0
void stitchTextures(const cmd::ArgumentList& args)
{
	// Get all the selected patches
	PatchPtrVector patchList = selection::algorithm::getSelectedPatches();

	if (patchList.size() == 2)
	{
		UndoableCommand undo("patchStitchTexture");

		// Fetch the instances from the selectionsystem
		const scene::INodePtr& targetNode =
			GlobalSelectionSystem().ultimateSelected();

		const scene::INodePtr& sourceNode =
			GlobalSelectionSystem().penultimateSelected();

		// Cast the instances onto a patch
		Patch* source = Node_getPatch(sourceNode);
		Patch* target = Node_getPatch(targetNode);

		if (source != NULL && target != NULL) {
			// Stitch the texture leaving the source patch intact
			target->stitchTextureFrom(*source);
		}
		else {
			gtkutil::MessageBox::ShowError(_("Cannot stitch textures. \nCould not cast nodes to patches."),
							 GlobalMainFrame().getTopLevelWindow());
		}

		SceneChangeNotify();
		// Update the Texture Tools
		ui::SurfaceInspector::update();
	}
	else
	{
		gtkutil::MessageBox::ShowError(_("Cannot stitch patch textures. \nExactly 2 patches must be selected."),
							 GlobalMainFrame().getTopLevelWindow());
	}
}
示例#2
0
void bulge(const cmd::ArgumentList& args)
{
	// Get the list of selected patches
	PatchPtrVector patches = selection::algorithm::getSelectedPatches();

	if (!patches.empty())
	{
		int maxValue = 16;

		// Ask the user to enter a noise value
		if (ui::BulgePatchDialog::queryPatchNoise(maxValue))
		{
			UndoableCommand cmd("BulgePatch");

			// Cycle through all patches and apply the bulge algorithm
			for (PatchPtrVector::iterator p = patches.begin(); p != patches.end(); ++p)
			{
				Patch& patch = (*p)->getPatchInternal();

				patch.undoSave();

				for (PatchControlIter i = patch.begin(); i != patch.end(); ++i)
				{
					PatchControl& control = *i;
					int randomNumber = int(maxValue * (float(std::rand()) / float(RAND_MAX)));
					control.vertex.set(control.vertex.x(), control.vertex.y(), control.vertex.z() + randomNumber);
				}

				patch.controlPointsChanged();
			}
		}
	}
	else
	{
		gtkutil::MessageBox::ShowError(_("Cannot bulge patch. No patches selected."),
			GlobalMainFrame().getTopLevelWindow());
	}
}
示例#3
0
void PatchInspector::rescanSelection()
{
	// Check if there is one distinct patch selected
	bool sensitive = (_selectionInfo.patchCount == 1);

	findNamedObject<wxPanel>(this, "PatchInspectorVertexPanel")->Enable(sensitive);
	findNamedObject<wxPanel>(this, "PatchInspectorCoordPanel")->Enable(sensitive);

	// Tesselation is always sensitive when one or more patches are selected
	findNamedObject<wxPanel>(this, "PatchInspectorTessPanel")->Enable(_selectionInfo.patchCount > 0);

	// Clear the patch reference
	setPatch(PatchNodePtr());

	if (_selectionInfo.patchCount > 0)
	{
		// Get the list of selected patches
		PatchPtrVector list = selection::algorithm::getSelectedPatches();

		Subdivisions tess(UINT_MAX, UINT_MAX);
		bool tessIsFixed = false;

		// Try to find a pair of same tesselation values
		for (PatchPtrVector::const_iterator i = list.begin(); i != list.end(); ++i)
        {
			IPatch& p = (*i)->getPatch();

			if (tess.x() == UINT_MAX)
            {
				// Not initialised yet, take these values for starters
				tessIsFixed = p.subdivionsFixed();
				tess = p.getSubdivisions();
			}
			else
			{
				// We already have a pair of divisions, compare
				Subdivisions otherTess = p.getSubdivisions();

				if (tessIsFixed != p.subdivionsFixed() || otherTess != tess)
				{
					// Our journey ends here, we cannot find a pair of tesselations
					// for all selected patches or the same fixed/variable status
					tessIsFixed = false;
					break;
				}
			}
		}

		_updateActive = true;

		// Load the "fixed tesselation" value
		findNamedObject<wxCheckBox>(this, "PatchInspectorFixedSubdivisions")->SetValue(tessIsFixed);

		wxSpinCtrl* fixedSubdivX = findNamedObject<wxSpinCtrl>(this, "PatchInspectorSubdivisionsX");
		wxSpinCtrl* fixedSubdivY = findNamedObject<wxSpinCtrl>(this, "PatchInspectorSubdivisionsY");

		fixedSubdivX->SetValue(tess[0]);
		fixedSubdivY->SetValue(tess[1]);

		fixedSubdivX->Enable(tessIsFixed);
		fixedSubdivY->Enable(tessIsFixed);

		findNamedObject<wxStaticText>(this, "PatchInspectorSubdivisionsXLabel")->Enable(tessIsFixed);
		findNamedObject<wxStaticText>(this, "PatchInspectorSubdivisionsYLabel")->Enable(tessIsFixed);

		if (_selectionInfo.patchCount == 1)
		{
			setPatch(list[0]);
		}

		_updateActive = false;
	}

	update();
}