simplify ParentSelectedBrushesToEntityWalker
add comments to EntitySetClassnameSelected
This commit is contained in:
parent
17a7e2f413
commit
66197713a5
|
|
@ -84,9 +84,10 @@ void post( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
class EntitySetClassnameSelected : public scene::Graph::Walker
|
class EntitySetClassnameSelected : public scene::Graph::Walker
|
||||||
{
|
{
|
||||||
const char* m_classname;
|
const char* m_classname;
|
||||||
|
scene::Node* m_world;
|
||||||
public:
|
public:
|
||||||
EntitySetClassnameSelected( const char* classname )
|
EntitySetClassnameSelected( const char* classname )
|
||||||
: m_classname( classname ){
|
: m_classname( classname ), m_world( Map_FindWorldspawn( g_map ) ){
|
||||||
}
|
}
|
||||||
bool pre( const scene::Path& path, scene::Instance& instance ) const {
|
bool pre( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -94,22 +95,19 @@ bool pre( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
void post( const scene::Path& path, scene::Instance& instance ) const {
|
void post( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
Entity* entity = Node_getEntity( path.top() );
|
Entity* entity = Node_getEntity( path.top() );
|
||||||
if ( entity != 0 && ( instance.childSelected() || Instance_getSelectable( instance )->isSelected() ) ) {
|
if ( entity != 0 && ( instance.childSelected() || Instance_getSelectable( instance )->isSelected() ) ) {
|
||||||
if( string_equal( entity->getKeyValue( "classname" ), "worldspawn" ) ){
|
if( path.top().get_pointer() == m_world ){ /* do not want to convert whole worldspawn entity */
|
||||||
//globalErrorStream() << "do not want to convert worldspawn entity\n";
|
if( instance.childSelected() ){ /* create an entity from world brushes instead */
|
||||||
|
|
||||||
if( instance.childSelected() ){
|
|
||||||
EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( m_classname, true );
|
EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( m_classname, true );
|
||||||
if( entityClass->fixedsize )
|
if( entityClass->fixedsize )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//is important to have retexturing here; if doing in the end, undo doesn't succeed;
|
//is important to have retexturing here; if doing in the end, undo doesn't succeed; //don't do this extra now, as it requires retexturing, working for subgraph
|
||||||
// if ( string_compare_nocase_n( m_classname, "trigger_", 8 ) == 0 ){
|
// if ( string_compare_nocase_n( m_classname, "trigger_", 8 ) == 0 ){
|
||||||
// Scene_PatchSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() );
|
// Scene_PatchSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() );
|
||||||
// Scene_BrushSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() );
|
// Scene_BrushSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
NodeSmartReference node( GlobalEntityCreator().createEntity( entityClass ) );
|
NodeSmartReference node( GlobalEntityCreator().createEntity( entityClass ) );
|
||||||
|
|
||||||
Node_getTraversable( GlobalSceneGraph().root() )->insert( node );
|
Node_getTraversable( GlobalSceneGraph().root() )->insert( node );
|
||||||
|
|
||||||
scene::Path entitypath( makeReference( GlobalSceneGraph().root() ) );
|
scene::Path entitypath( makeReference( GlobalSceneGraph().root() ) );
|
||||||
|
|
@ -128,35 +126,28 @@ void post( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityClass* eclass = GlobalEntityClassManager().findOrInsert( m_classname, node_is_group( path.top() ) );
|
EntityClass* eclass = GlobalEntityClassManager().findOrInsert( m_classname, node_is_group( path.top() ) );
|
||||||
//NodeSmartReference node( GlobalEntityCreator().createEntity( GlobalEntityClassManager().findOrInsert( m_classname, node_is_group( path.top() ) ) ) );
|
|
||||||
NodeSmartReference node( GlobalEntityCreator().createEntity( eclass ) );
|
NodeSmartReference node( GlobalEntityCreator().createEntity( eclass ) );
|
||||||
|
|
||||||
if( eclass->fixedsize && entity->isContainer() ){
|
if( entity->isContainer() && eclass->fixedsize ){ /* group entity to point one */
|
||||||
//group to point entity
|
|
||||||
char value[64];
|
char value[64];
|
||||||
sprintf( value, "%g %g %g", instance.worldAABB().origin[0], instance.worldAABB().origin[1], instance.worldAABB().origin[2] );
|
sprintf( value, "%g %g %g", instance.worldAABB().origin[0], instance.worldAABB().origin[1], instance.worldAABB().origin[2] );
|
||||||
entity->setKeyValue( "origin", value );
|
entity->setKeyValue( "origin", value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityCopyingVisitor visitor( *Node_getEntity( node ) );
|
EntityCopyingVisitor visitor( *Node_getEntity( node ) );
|
||||||
|
// entity->forEachKeyValue( visitor );
|
||||||
//entity->forEachKeyValue( visitor );
|
|
||||||
|
|
||||||
NodeSmartReference child( path.top().get() );
|
NodeSmartReference child( path.top().get() );
|
||||||
NodeSmartReference parent( path.parent().get() );
|
NodeSmartReference parent( path.parent().get() );
|
||||||
//Node_getTraversable( parent )->erase( child );
|
// Node_getTraversable( parent )->erase( child );
|
||||||
if ( Node_getTraversable( child ) != 0
|
if ( Node_getTraversable( child ) != 0 && node_is_group( node ) ) { /* group entity to group one */
|
||||||
&& Node_getTraversable( node ) != 0
|
|
||||||
&& node_is_group( node ) ) {
|
|
||||||
parentBrushes( child, node );
|
parentBrushes( child, node );
|
||||||
}
|
}
|
||||||
Node_getTraversable( parent )->insert( node );
|
Node_getTraversable( parent )->insert( node );
|
||||||
/* must do this after inserting node, otherwise problem: targeted + having model + not loaded b4 new entities aren't selectable normally + rendered only while 0 0 0 is rendered */
|
|
||||||
entity->forEachKeyValue( visitor );
|
entity->forEachKeyValue( visitor ); /* must do this after inserting node, otherwise problem: targeted + having model + not loaded b4 new entities aren't selectable normally + rendered only while 0 0 0 is rendered */
|
||||||
if( !eclass->fixedsize && !entity->isContainer() ){
|
|
||||||
//globalErrorStream() << "can't convert point to group entity\n";
|
if( !entity->isContainer() && !eclass->fixedsize ){ /* point entity to group one */
|
||||||
//return;
|
|
||||||
AABB bounds( g_vector3_identity, Vector3( 16, 16, 16 ) );
|
AABB bounds( g_vector3_identity, Vector3( 16, 16, 16 ) );
|
||||||
if ( !string_parse_vector3( entity->getKeyValue( "origin" ), bounds.origin ) ) {
|
if ( !string_parse_vector3( entity->getKeyValue( "origin" ), bounds.origin ) ) {
|
||||||
bounds.origin = g_vector3_identity;
|
bounds.origin = g_vector3_identity;
|
||||||
|
|
@ -164,6 +155,7 @@ void post( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
Brush_ConstructPlacehoderCuboid( node.get(), bounds );
|
Brush_ConstructPlacehoderCuboid( node.get(), bounds );
|
||||||
Node_getEntity( node )->setKeyValue( "origin", "" );
|
Node_getEntity( node )->setKeyValue( "origin", "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
Node_getTraversable( parent )->erase( child );
|
Node_getTraversable( parent )->erase( child );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1829,47 +1829,29 @@ bool Map_SaveSelected( const char* filename ){
|
||||||
class ParentSelectedBrushesToEntityWalker : public scene::Graph::Walker
|
class ParentSelectedBrushesToEntityWalker : public scene::Graph::Walker
|
||||||
{
|
{
|
||||||
scene::Node& m_parent;
|
scene::Node& m_parent;
|
||||||
|
scene::Node* m_world;
|
||||||
mutable bool m_emptyOldParent;
|
mutable bool m_emptyOldParent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ParentSelectedBrushesToEntityWalker( scene::Node& parent ) : m_parent( parent ), m_emptyOldParent( false ){
|
ParentSelectedBrushesToEntityWalker( scene::Node& parent ) : m_parent( parent ), m_world( Map_FindWorldspawn( g_map ) ), m_emptyOldParent( false ){
|
||||||
}
|
}
|
||||||
bool pre( const scene::Path& path, scene::Instance& instance ) const {
|
bool pre( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
if ( path.top().get_pointer() != &m_parent && ( Node_isPrimitive( path.top() ) || m_emptyOldParent ) ) {
|
return path.top().get_pointer() != &m_parent; /* skip traverse of target node */
|
||||||
Selectable* selectable = Instance_getSelectable( instance );
|
|
||||||
if ( selectable && selectable->isSelected() && path.size() > 1 ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
void post( const scene::Path& path, scene::Instance& instance ) const {
|
void post( const scene::Path& path, scene::Instance& instance ) const {
|
||||||
if ( path.top().get_pointer() == &m_parent )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( Node_isPrimitive( path.top() ) ){
|
if ( Node_isPrimitive( path.top() ) ){
|
||||||
m_emptyOldParent = false;
|
|
||||||
Selectable* selectable = Instance_getSelectable( instance );
|
Selectable* selectable = Instance_getSelectable( instance );
|
||||||
|
if ( selectable && selectable->isSelected() ){
|
||||||
if ( selectable && selectable->isSelected() && path.size() > 1 ){
|
NodeSmartReference node( path.top().get() );
|
||||||
scene::Node& parent = path.parent();
|
scene::Traversable* parent_traversable = Node_getTraversable( path.parent() );
|
||||||
if ( &parent != &m_parent ){
|
parent_traversable->erase( node );
|
||||||
NodeSmartReference node( path.top().get() );
|
Node_getTraversable( m_parent )->insert( node );
|
||||||
scene::Traversable* traversable_parent = Node_getTraversable( parent );
|
m_emptyOldParent = parent_traversable->empty();
|
||||||
traversable_parent->erase( node );
|
|
||||||
Node_getTraversable( m_parent )->insert( node );
|
|
||||||
if ( traversable_parent->empty() )
|
|
||||||
m_emptyOldParent = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_emptyOldParent ){
|
else if ( m_emptyOldParent ){
|
||||||
m_emptyOldParent = false;
|
m_emptyOldParent = false;
|
||||||
// delete empty entities
|
if ( Node_isEntity( path.top() ) && path.top().get_pointer() != m_world && Node_getTraversable( path.top() )->empty() ) /* delete empty entity left */
|
||||||
Entity* entity = Node_getEntity( path.top() );
|
|
||||||
if ( entity != 0 && path.top().get_pointer() != Map_FindWorldspawn( g_map ) && Node_getTraversable( path.top() )->empty() ) {
|
|
||||||
Path_deleteTop( path );
|
Path_deleteTop( path );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user