47 if (ImGui::IsMouseClicked(2))
49 ImVec2 mouse_screen = ImGui::GetIO().MousePos / ImGui::GetIO().DisplaySize;
52 float min_dist = std::numeric_limits<float>::max();
53 Vector3 origin = terrain_editor_mouse_ray.getOrigin();
54 Vector3 direction = terrain_editor_mouse_ray.getDirection();
55 for (
int i = 0; i < (int)object_list.size(); i++)
57 Real ray_object_distance = direction.crossProduct(object_list[i]->getPosition() - origin).length();
58 if (ray_object_distance < min_dist)
60 min_dist = ray_object_distance;
77 float min_dist = std::numeric_limits<float>::max();
78 for (
int i = 0; i < (int)object_list.size(); i++)
80 float dist = ref_pos.squaredDistance(object_list[i]->getPosition());
104 catch (std::exception& e)
111 if (object_list.size() > 0)
119 if (object_list.size() > 0)
127 std::string axis =
_L(
"ry");
143 std::string ssmsg =
_L(
"Rotating: ") + axis;
149 std::string ssmsg =
m_object_tracking ?
_L(
"Enabled object tracking") :
_L(
"Disabled object tracking");
159 Vector3 translation = Vector3::ZERO;
160 float rotation = 0.0f;
172 translation.y += 0.5f;
176 translation.y -= 0.5f;
180 translation.x += 0.5f;
184 translation.x -= 0.5f;
188 translation.z += 0.5f;
192 translation.z -= 0.5f;
195 if (translation != Vector3::ZERO || rotation != 0.0f)
202 new_position += translation * scale * dt;
241 const char* filename =
"editor_out.log";
245 Ogre::DataStreamPtr stream
246 = Ogre::ResourceGroupManager::getSingleton().createResource(
251 SceneNode* sn =
object->static_object_node;
254 String pos = StringUtil::format(
"%8.3f, %8.3f, %8.3f", object->position.x, object->position.y, object->position.z);
255 String rot = StringUtil::format(
"% 6.1f, % 6.1f, % 6.1f", object->rotation.x, object->rotation.y, object->rotation.z);
257 String line = pos +
", " + rot +
", " +
object->name +
"\n";
258 stream->write(line.c_str(), line.length());
264 for (
int i = 0; i < num_roads; i++)
270 stream->write(
"\nbegin_procedural_roads\n", 24);
271 for (
int j = 0; j < num_points; j++)
274 std::string type_str;
282 case RoadType::ROAD_BRIDGE: type_str = (point->pillartype == 1) ?
"bridge" :
"bridge_no_pillars";
break;
286 Ogre::Matrix3 point_rot_matrix;
287 point->rotation.ToRotationMatrix(point_rot_matrix);
288 Ogre::Radian yaw, pitch, roll;
289 point_rot_matrix.ToEulerAnglesYXZ(yaw, pitch, roll);
291 std::string line = fmt::format(
292 "\t{:13f}, {:13f}, {:13f}, 0, {:13f}, 0, {:13f}, {:13f}, {:13f}, {}\n",
293 point->position.x, point->position.y, point->position.z,
295 point->width, point->bwidth, point->bheight, type_str);
296 stream->write(line.c_str(), line.length());
298 stream->write(
"end_procedural_roads\n", 21);
302 catch (std::exception& e)
305 "Error saving file '%s' (resource group '%s'), message: '%s'",
325 fmt::format(
"Cannot export terrain editor changes - terrain is not a project"));
330 for (
size_t i = 0; i < terrain->
getObjectManager()->GetTobjCache().size(); i++)
334 tobj->objects.clear();
335 tobj->vehicles.clear();
338 if (src->tobj_cache_id == i)
351 tobj->objects.push_back(dst);
359 dst.
type = src->special_object_type;
361 tobj->vehicles.push_back(dst);
368 Ogre::DataStreamPtr stream
369 = Ogre::ResourceGroupManager::getSingleton().createResource(
376 fmt::format(
"Error saving file '{}' to resource group '{}'",
436 LOG(fmt::format(
"[RoR|TerrainEditor] INTERNAL ERROR - `m_selected_object_id` '{}' >= `(int)object_list.size()` '{}'",
500 static_object_node->setOrientation(Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z));
System integration layer; inspired by OgreBites::ApplicationContext.
#define ROR_ASSERT(_EXPR)
void LOG(const char *msg)
Legacy alias - formerly a macro.
Game state manager and message-queue provider.
void TerrainEditorObjectRefreshActorVisual(TerrainEditorObjectPtr obj)
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
const ActorPtr & GetActorById(ActorInstanceID_t actor_id)
static const ActorPtr ACTORPTR_NULL
std::string resource_bundle_type
Archive type recognized by OGRE resource system: 'FileSystem' or 'Zip'.
Ogre::SceneNode * GetCameraNode()
CameraBehaviors GetCurrentBehavior() const
Ogre::Camera * GetCamera()
void setPosition(Ogre::Vector3 position)
Ogre::Vector3 getPosition()
@ CONSOLE_MSGTYPE_INFO
Generic message.
@ CONSOLE_MSGTYPE_TERRN
Parsing/spawn/simulation messages for terrain.
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
@ CONSOLE_SYSTEM_REPLY
Success.
CharacterFactory * GetCharacterFactory()
Character * GetPlayerCharacter()
const TerrainPtr & GetTerrain()
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
ActorManager * GetActorManager()
ProceduralObjectPtr getObject(int pos)
static Ogre::Quaternion CalcRotation(Ogre::Vector3 const &rot, bool rot_yxz)
void ClearSelectedObject()
void WriteSeparateOutputFile()
Writes 'editor_out.log' to 'config' directory - original solution, still used for zipped terrains.
void UpdateInputEvents(float dt)
TerrainEditorObjectID_t GetSelectedObjectID() const
void SetSelectedObjectByID(TerrainEditorObjectID_t id)
std::string m_last_object_name
const TerrainEditorObjectPtr & FetchSelectedObject()
TerrainEditorObjectID_t m_selected_object_id
int m_rotation_axis
0=X, 1=Y, 2=Z
static const TerrainEditorObjectPtr TERRAINEDITOROBJECTPTR_NULL
void WriteEditsToTobjFiles()
Updates existing TOBJ files - new solution, only for projects (unzipped terrains).
ActorInstanceID_t getActorInstanceId()
std::string const & getType()
Ogre::Vector3 const & getPosition()
ActorInstanceID_t actor_instance_id
void setSpecialObjectType(TObjSpecialObject type)
void setActorInstanceId(ActorInstanceID_t instance_id)
std::string const & getName()
TObjSpecialObject special_object_type
void setPosition(Ogre::Vector3 const &pos)
std::string instance_name
std::string const & getInstanceName()
Ogre::SceneNode * static_object_node
void setRotation(Ogre::Vector3 const &rot)
TObjSpecialObject getSpecialObjectType()
std::string type
Accepts "-" as placeholder, otherwise a surveymap icon is registered.
Ogre::Vector3 const & getRotation()
std::string getTerrainFileResourceGroup()
TerrainObjectManager * getObjectManager()
CacheEntryPtr getCacheEntry()
ProceduralManagerPtr getProceduralManager()
bool LoadTerrainObject(const Ogre::String &name, const Ogre::Vector3 &pos, const Ogre::Vector3 &rot, const Ogre::String &instancename, const Ogre::String &type, float rendering_distance=0, bool enable_collisions=true, int scripthandler=-1, bool uniquifyMaterial=false)
TerrainEditorObjectPtrVec & GetEditorObjects()
bool GetEditorObjectFlagRotYXZ(TerrainEditorObjectPtr const &object)
std::vector< TObjDocumentPtr > & GetTobjCache()
void SpawnSinglePredefinedActor(TerrainEditorObjectPtr const &object)
void destroyObject(const Ogre::String &instancename)
std::string PathCombine(std::string a, std::string b)
@ MSG_EDI_LEAVE_TERRN_EDITOR_REQUESTED
@ MSG_SIM_MODIFY_ACTOR_REQUESTED
Payload = RoR::ActorModifyRequest* (owner)
InputEngine * GetInputEngine()
CameraManager * GetCameraManager()
GameContext * GetGameContext()
void WriteToStream(TObjDocumentPtr doc, Ogre::DataStreamPtr stream)
std::shared_ptr< TObjDocument > TObjDocumentPtr
void HandleGenericException(const std::string &from, BitMask_t flags)
int ActorInstanceID_t
Unique sequentially generated ID of an actor in session. Use ActorManager::GetActorById()
int TerrainEditorObjectID_t
Offset into RoR::TerrainObjectManager::m_editor_objects, use RoR::TERRAINEDITOROBJECTID_INVALID as em...
void LogFormat(const char *format,...)
Improved logging utility. Uses fixed 2Kb buffer.
static const ActorInstanceID_t ACTORINSTANCEID_INVALID
@ HANDLEGENERICEXCEPTION_CONSOLE
static const TerrainEditorObjectID_t TERRAINEDITOROBJECTID_INVALID
ActorInstanceID_t amr_actor
Ogre::Quaternion amr_softrespawn_rotation
Rotation to use with SOFT_RESPAWN; use TObjParser::CalcRotation() to calculate quaternion from XYZ li...
Ogre::Vector3 amr_softrespawn_position
Position to use with SOFT_RESPAWN.
@ SOFT_RESPAWN
Like hard reset, but positions the actor like spawn process does - using the relative positions from ...
@ REFRESH_VISUALS
Forces a synchronous update of visuals from any context - i.e. from terrain editor mode or with sleep...
Unified game event system - all requests and state changes are reported using a message.
ProceduralPointPtr getPoint(int pos)
char instance_name[TObj::STR_LEN]
char odef_name[TObj::STR_LEN]
std::string comments
Comment line(s) preceding the object-line in the .TOBJ file.
Ogre::Vector3 tobj_rotation
Original rotation specified in .TOBJ file.