|
|
|
@ -320,26 +320,8 @@ CSVRender::InstanceMode::InstanceMode(
|
|
|
|
|
connect(
|
|
|
|
|
duplicateShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this, &InstanceMode::cloneSelectedInstances);
|
|
|
|
|
|
|
|
|
|
// Following classes could be simplified by using QSignalMapper, which is obsolete in Qt5.10, but not in Qt4.8 and
|
|
|
|
|
// Qt5.14
|
|
|
|
|
CSMPrefs::Shortcut* dropToCollisionShortcut
|
|
|
|
|
= new CSMPrefs::Shortcut("scene-instance-drop-collision", worldspaceWidget);
|
|
|
|
|
|
|
|
|
|
connect(dropToCollisionShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this,
|
|
|
|
|
&InstanceMode::dropSelectedInstancesToCollision);
|
|
|
|
|
|
|
|
|
|
CSMPrefs::Shortcut* dropToTerrainLevelShortcut
|
|
|
|
|
= new CSMPrefs::Shortcut("scene-instance-drop-terrain", worldspaceWidget);
|
|
|
|
|
connect(dropToTerrainLevelShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this,
|
|
|
|
|
&InstanceMode::dropSelectedInstancesToTerrain);
|
|
|
|
|
CSMPrefs::Shortcut* dropToCollisionShortcut2
|
|
|
|
|
= new CSMPrefs::Shortcut("scene-instance-drop-collision-separately", worldspaceWidget);
|
|
|
|
|
connect(dropToCollisionShortcut2, qOverload<>(&CSMPrefs::Shortcut::activated), this,
|
|
|
|
|
&InstanceMode::dropSelectedInstancesToCollisionSeparately);
|
|
|
|
|
CSMPrefs::Shortcut* dropToTerrainLevelShortcut2
|
|
|
|
|
= new CSMPrefs::Shortcut("scene-instance-drop-terrain-separately", worldspaceWidget);
|
|
|
|
|
connect(dropToTerrainLevelShortcut2, qOverload<>(&CSMPrefs::Shortcut::activated), this,
|
|
|
|
|
&InstanceMode::dropSelectedInstancesToTerrainSeparately);
|
|
|
|
|
connect(new CSMPrefs::Shortcut("scene-instance-drop", worldspaceWidget),
|
|
|
|
|
qOverload<>(&CSMPrefs::Shortcut::activated), this, &InstanceMode::dropToCollision);
|
|
|
|
|
|
|
|
|
|
for (short i = 0; i <= 9; i++)
|
|
|
|
|
{
|
|
|
|
@ -1254,7 +1236,7 @@ void CSVRender::InstanceMode::dropInstance(CSVRender::Object* object, float drop
|
|
|
|
|
object->setPosition(position.pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float CSVRender::InstanceMode::calculateDropHeight(DropMode dropMode, CSVRender::Object* object, float objectHeight)
|
|
|
|
|
float CSVRender::InstanceMode::calculateDropHeight(CSVRender::Object* object, float objectHeight)
|
|
|
|
|
{
|
|
|
|
|
osg::Vec3d point = object->getPosition().asVec3();
|
|
|
|
|
|
|
|
|
@ -1268,10 +1250,7 @@ float CSVRender::InstanceMode::calculateDropHeight(DropMode dropMode, CSVRender:
|
|
|
|
|
intersector->setIntersectionLimit(osgUtil::LineSegmentIntersector::NO_LIMIT);
|
|
|
|
|
osgUtil::IntersectionVisitor visitor(intersector);
|
|
|
|
|
|
|
|
|
|
if (dropMode & Terrain)
|
|
|
|
|
visitor.setTraversalMask(Mask_Terrain);
|
|
|
|
|
if (dropMode & Collision)
|
|
|
|
|
visitor.setTraversalMask(Mask_Terrain | Mask_Reference);
|
|
|
|
|
visitor.setTraversalMask(Mask_Terrain | Mask_Reference);
|
|
|
|
|
|
|
|
|
|
mParentNode->accept(visitor);
|
|
|
|
|
|
|
|
|
@ -1286,27 +1265,7 @@ float CSVRender::InstanceMode::calculateDropHeight(DropMode dropMode, CSVRender:
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVRender::InstanceMode::dropSelectedInstancesToCollision()
|
|
|
|
|
{
|
|
|
|
|
handleDropMethod(Collision, "Drop instances to next collision");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVRender::InstanceMode::dropSelectedInstancesToTerrain()
|
|
|
|
|
{
|
|
|
|
|
handleDropMethod(Terrain, "Drop instances to terrain level");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVRender::InstanceMode::dropSelectedInstancesToCollisionSeparately()
|
|
|
|
|
{
|
|
|
|
|
handleDropMethod(CollisionSep, "Drop instances to next collision level separately");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVRender::InstanceMode::dropSelectedInstancesToTerrainSeparately()
|
|
|
|
|
{
|
|
|
|
|
handleDropMethod(TerrainSep, "Drop instances to terrain level separately");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVRender::InstanceMode::handleDropMethod(DropMode dropMode, QString commandMsg)
|
|
|
|
|
void CSVRender::InstanceMode::dropToCollision()
|
|
|
|
|
{
|
|
|
|
|
std::vector<osg::ref_ptr<TagBase>> selection = getWorldspaceWidget().getSelection(Mask_Reference);
|
|
|
|
|
if (selection.empty())
|
|
|
|
@ -1315,43 +1274,19 @@ void CSVRender::InstanceMode::handleDropMethod(DropMode dropMode, QString comman
|
|
|
|
|
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
|
|
|
|
|
QUndoStack& undoStack = document.getUndoStack();
|
|
|
|
|
|
|
|
|
|
CSMWorld::CommandMacro macro(undoStack, commandMsg);
|
|
|
|
|
CSMWorld::CommandMacro macro(undoStack, "Drop objects to collision");
|
|
|
|
|
|
|
|
|
|
DropObjectHeightHandler dropObjectDataHandler(&getWorldspaceWidget());
|
|
|
|
|
|
|
|
|
|
if (dropMode & Separate)
|
|
|
|
|
{
|
|
|
|
|
int counter = 0;
|
|
|
|
|
for (osg::ref_ptr<TagBase> tag : selection)
|
|
|
|
|
if (CSVRender::ObjectTag* objectTag = dynamic_cast<CSVRender::ObjectTag*>(tag.get()))
|
|
|
|
|
{
|
|
|
|
|
float objectHeight = dropObjectDataHandler.mObjectHeights[counter];
|
|
|
|
|
float dropHeight = calculateDropHeight(dropMode, objectTag->mObject, objectHeight);
|
|
|
|
|
dropInstance(objectTag->mObject, dropHeight);
|
|
|
|
|
objectTag->mObject->apply(macro);
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
float smallestDropHeight = std::numeric_limits<float>::max();
|
|
|
|
|
int counter = 0;
|
|
|
|
|
for (osg::ref_ptr<TagBase> tag : selection)
|
|
|
|
|
if (CSVRender::ObjectTag* objectTag = dynamic_cast<CSVRender::ObjectTag*>(tag.get()))
|
|
|
|
|
{
|
|
|
|
|
float objectHeight = dropObjectDataHandler.mObjectHeights[counter];
|
|
|
|
|
float thisDrop = calculateDropHeight(dropMode, objectTag->mObject, objectHeight);
|
|
|
|
|
if (thisDrop < smallestDropHeight)
|
|
|
|
|
smallestDropHeight = thisDrop;
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
for (osg::ref_ptr<TagBase> tag : selection)
|
|
|
|
|
if (CSVRender::ObjectTag* objectTag = dynamic_cast<CSVRender::ObjectTag*>(tag.get()))
|
|
|
|
|
{
|
|
|
|
|
dropInstance(objectTag->mObject, smallestDropHeight);
|
|
|
|
|
objectTag->mObject->apply(macro);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int counter = 0;
|
|
|
|
|
for (osg::ref_ptr<TagBase> tag : selection)
|
|
|
|
|
if (CSVRender::ObjectTag* objectTag = dynamic_cast<CSVRender::ObjectTag*>(tag.get()))
|
|
|
|
|
{
|
|
|
|
|
float objectHeight = dropObjectDataHandler.mObjectHeights[counter++];
|
|
|
|
|
float dropHeight = calculateDropHeight(objectTag->mObject, objectHeight);
|
|
|
|
|
dropInstance(objectTag->mObject, dropHeight);
|
|
|
|
|
objectTag->mObject->apply(macro);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSVRender::DropObjectHeightHandler::DropObjectHeightHandler(WorldspaceWidget* worldspacewidget)
|
|
|
|
|