示例#1
0
void Entity_ungroupSelected(){
	if ( GlobalSelectionSystem().countSelected() < 1 ) {
		return;
	}

	UndoableCommand undo( "ungroupSelectedEntities" );

	scene::Path world_path( makeReference( GlobalSceneGraph().root() ) );
	world_path.push( makeReference( Map_FindOrInsertWorldspawn( g_map ) ) );

	scene::Instance &instance = GlobalSelectionSystem().ultimateSelected();
	scene::Path path = instance.path();

	if ( !Node_isEntity( path.top() ) ) {
		path.pop();
	}

	if ( Node_getEntity( path.top() ) != 0
		 && node_is_group( path.top() ) ) {
		if ( world_path.top().get_pointer() != path.top().get_pointer() ) {
			parentBrushes( path.top(), world_path.top() );
			Path_deleteTop( path );
		}
	}
}
示例#2
0
void post( const scene::Path& path, scene::Instance& instance ) const {
	Entity* entity = Node_getEntity( path.top() );
	if ( entity != 0
		 && Instance_getSelectable( instance )->isSelected()
		 && node_is_group( path.top() )
		 && !groupPath ) {
		groupPath = &path;
		groupInstance = &instance;
	}
}
示例#3
0
 void visit(scene::Instance& instance) const
 {
   if(Node_getEntity(instance.path().top()) != 0
     && node_is_group(instance.path().top()))
   {
     if(m_parent.top().get_pointer() != instance.path().top().get_pointer())
     {
       parentBrushes(instance.path().top(), m_parent.top());
       Path_deleteTop(instance.path());
     }
   }
 }
示例#4
0
/// moves selected primitives to entity, which is or its primitive is ultimateSelected() or firstSelected()
void Entity_moveSelectedPrimitives( bool toLast ){
	if ( GlobalSelectionSystem().countSelected() < 2 ) {
		globalErrorStream() << "Source and target entity primitives should be selected!\n";
		return;
	}

	const scene::Path& path = toLast? GlobalSelectionSystem().ultimateSelected().path() : GlobalSelectionSystem().firstSelected().path();
	scene::Node& node = ( !Node_isEntity( path.top() ) && path.size() > 1 )? path.parent() : path.top();

	if ( Node_isEntity( node ) && node_is_group( node ) ) {
		StringOutputStream command;
		command << "movePrimitivesToEntity " << makeQuoted( Node_getEntity( node )->getEntityClass().name() );
		UndoableCommand undo( command.c_str() );
		Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node );
	}
}
示例#5
0
	bool pre(const scene::INodePtr& node)
	{
		// Ignore hidden nodes
		if (!node->visible()) return false;

		Entity* entity = Node_getEntity(node);

		// Check if we have a selectable
		SelectablePtr selectable = Node_getSelectable(node);

		if (selectable != NULL)
		{
			switch (_mode)
			{
				case SelectionSystem::eEntity:
					if (entity != NULL && entity->getKeyValue("classname") != "worldspawn")
					{
						_selectable = selectable;
					}
					break;
				case SelectionSystem::ePrimitive:
					_selectable = selectable;
					break;
				case SelectionSystem::eComponent:
					// Check if we have a componentselectiontestable instance
					ComponentSelectionTestablePtr compSelTestable = 
						Node_getComponentSelectionTestable(node);

					// Only add it to the list if the instance has components and is already selected
					if (compSelTestable != NULL && selectable->isSelected())
					{
						_selectable = selectable;
					}
					break;
			}
		}
		
		// Do we have a groupnode? If yes, don't traverse the children
		if (entity != NULL && node_is_group(node) && 
			entity->getKeyValue("classname") != "worldspawn") 
		{
			// Don't traverse the children of this groupnode
			return false;
		}

		return true;
	}
示例#6
0
void post( const scene::Path& path, scene::Instance& instance ) const {
	Entity* entity = Node_getEntity( path.top() );
	if ( entity != 0
		 && ( instance.childSelected() || Instance_getSelectable( instance )->isSelected() ) ) {
		NodeSmartReference node( GlobalEntityCreator().createEntity( GlobalEntityClassManager().findOrInsert( m_classname, node_is_group( path.top() ) ) ) );

		EntityCopyingVisitor visitor( *Node_getEntity( node ) );

		entity->forEachKeyValue( visitor );

		NodeSmartReference child( path.top().get() );
		NodeSmartReference parent( path.parent().get() );
		Node_getTraversable( parent )->erase( child );
		if ( Node_getTraversable( child ) != 0
			 && Node_getTraversable( node ) != 0
			 && node_is_group( node ) ) {
			parentBrushes( child, node );
		}
		Node_getTraversable( parent )->insert( node );
	}
}
示例#7
0
void Entity_ungroupSelected(){
	if ( GlobalSelectionSystem().countSelected() < 1 ) {
		return;
	}

	UndoableCommand undo( "ungroupSelectedEntities" );

	scene::Instance &instance = GlobalSelectionSystem().ultimateSelected();
	scene::Path path = instance.path();

	scene::Node& world = Map_FindOrInsertWorldspawn( g_map );

	if ( !Node_isEntity( path.top() ) && path.size() > 1 ) {
		path.pop();
	}

	if ( Node_isEntity( path.top() )
		 && node_is_group( path.top() ) ) {
		if ( &world != path.top().get_pointer() ) {
			parentBrushes( path.top(), world );
			Path_deleteTop( path );
		}
	}
}
示例#8
0
void popElement( const char* name ){
	ASSERT_MESSAGE( string_equal( name, "entity" ), PARSE_ERROR );
	NodeSmartReference entity( m_entityTable.createEntity( GlobalEntityClassManager().findOrInsert( Node_getEntity( node() )->getKeyValue( "classname" ), node_is_group( node() ) ) ) );

	{
		EntityCopyingVisitor visitor( *Node_getEntity( entity ) );
		Node_getEntity( node() )->forEachKeyValue( visitor );
	}

	if ( Node_getTraversable( entity ) != 0 && !Node_getEntity( entity )->getEntityClass().fixedsize ) {
		parentBrushes( node(), entity );
	}

	Node_getTraversable( m_parent )->insert( entity );

	destructor( primitive() );
	destructor( node() );
}
示例#9
0
void post( const scene::Path& path, scene::Instance& instance ) const {
	Entity* entity = Node_getEntity( path.top() );
	if ( entity != 0 && ( instance.childSelected() || Instance_getSelectable( instance )->isSelected() ) ) {
		if( path.top().get_pointer() == m_world ){ /* do not want to convert whole worldspawn entity */
			if( instance.childSelected() && !m_2world ){ /* create an entity from world brushes instead */
				EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( m_classname, true );
				if( entityClass->fixedsize )
					return;

				//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 ){
//					Scene_PatchSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() );
//					Scene_BrushSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() );
//				}

				NodeSmartReference node( GlobalEntityCreator().createEntity( entityClass ) );
				Node_getTraversable( GlobalSceneGraph().root() )->insert( node );

				scene::Path entitypath( makeReference( GlobalSceneGraph().root() ) );
				entitypath.push( makeReference( node.get() ) );
				scene::Instance& entityInstance = findInstance( entitypath );

				if ( g_pGameDescription->mGameType == "doom3" ) {
					Node_getEntity( node )->setKeyValue( "model", Node_getEntity( node )->getKeyValue( "name" ) );
				}

				//Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node );
				Scene_parentSubgraphSelectedBrushesToEntity( GlobalSceneGraph(), node, path );
				Scene_forEachChildSelectable( SelectableSetSelected( true ), entityInstance.path() );
			}
			return;
		}
		else if( m_2world ){ /* ungroupSelectedEntities */ //condition is skipped with world = 0, so code next to this may create multiple worldspawns; todo handle this very special case?
			if( node_is_group( path.top() ) ){
				parentBrushes( path.top(), *m_world );
				Path_deleteTop( path );
			}
			return;
		}

		EntityClass* eclass = GlobalEntityClassManager().findOrInsert( m_classname, node_is_group( path.top() ) );
		NodeSmartReference node( GlobalEntityCreator().createEntity( eclass ) );

		if( entity->isContainer() && eclass->fixedsize ){ /* group entity to point one */
			char value[64];
			sprintf( value, "%g %g %g", instance.worldAABB().origin[0], instance.worldAABB().origin[1], instance.worldAABB().origin[2] );
			entity->setKeyValue( "origin", value );
		}

		EntityCopyingVisitor visitor( *Node_getEntity( node ) );
//		entity->forEachKeyValue( visitor );

		NodeSmartReference child( path.top().get() );
		NodeSmartReference parent( path.parent().get() );
//		Node_getTraversable( parent )->erase( child );
		if ( Node_getTraversable( child ) != 0 && node_is_group( node ) ) { /* group entity to group one */
			parentBrushes( child, node );
		}
		Node_getTraversable( parent )->insert( node );

		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( !entity->isContainer() && !eclass->fixedsize ){ /* point entity to group one */
			AABB bounds( g_vector3_identity, Vector3( 16, 16, 16 ) );
			if ( !string_parse_vector3( entity->getKeyValue( "origin" ), bounds.origin ) ) {
				bounds.origin = g_vector3_identity;
			}
			Brush_ConstructPlacehoderCuboid( node.get(), bounds );
			Node_getEntity( node )->setKeyValue( "origin", "" );
		}

		Node_getTraversable( parent )->erase( child );
	}
}