std::list<DPatch> DPatch::SplitCols(){ std::list<DPatch> patchList; int i; int x, y; if ( height >= 5 ) { for ( i = 0; i < ( height - 1 ) / 2; i++ ) { DPatch p; p.width = width; p.height = MIN_PATCH_HEIGHT; p.SetTexture( texture ); for ( x = 0; x < p.width; x++ ) { for ( y = 0; y < MIN_PATCH_HEIGHT; y++ ) { p.points[x][y] = points[x][( i * 2 ) + y]; } } patchList.push_back( p ); } } else { //globalErrorStream() << "bobToolz SplitPatchRows: Patch has not enough rows for splitting.\n"; patchList.push_back( *this ); } return patchList; }
std::list<DPatch> DPatch::SplitRows(){ std::list<DPatch> patchList; int i; int x, y; if ( width >= 5 ) { for ( i = 0; i < ( width - 1 ) / 2; i++ ) { DPatch p; p.width = MIN_PATCH_WIDTH; p.height = height; p.SetTexture( texture ); for ( x = 0; x < MIN_PATCH_WIDTH; x++ ) { for ( y = 0; y < p.height; y++ ) { p.points[x][y] = points[( i * 2 ) + x][y]; } } patchList.push_back( p ); } } else { patchList.push_back( *this ); } return patchList; }
void DoSplitPatch() { DPatch patch; // ensure we have something selected if ( g_FuncTable.m_pfnSelectedBrushCount() != 1 ) { DoMessageBox( "Invalid number of objects selected, select 1 patch only", "Error", MB_OK ); return; } g_FuncTable.m_pfnAllocateSelectedBrushHandles(); brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle( 0 ); if ( !brush->pPatch ) { g_FuncTable.m_pfnReleaseSelectedBrushHandles(); DoMessageBox( "You must select ONLY patches", "Error", MB_OK ); return; } patch.LoadFromBrush_t( brush ); list<DPatch> patchList = patch.Split( true, true ); for ( list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++ ) { ( *patches ).BuildInRadiant(); } patch.RemoveFromRadiant(); g_FuncTable.m_pfnReleaseSelectedBrushHandles(); }
bool DEntity::LoadFromEntity( entity_t* ent, bool bLoadPatches ) { ClearPatches(); ClearBrushes(); ClearEPairs(); QER_Entity = ent; epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList( QER_Entity ); LoadEPairList( epl ); bool keep = FALSE; int i; for ( i = 0; brushEntityList[i]; i++ ) { if ( !stricmp( brushEntityList[i], m_Classname ) ) { keep = TRUE; break; } } if ( !keep ) { return FALSE; } int count = g_FuncTable.m_pfnAllocateEntityBrushHandles( QER_Entity ); for ( i = 0; i < count; i++ ) { brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle( i ); if ( brush == NULL ) { DoMessageBox( "GTKRadiant returned a NULL pointer, NOT a good sign", "WARNING!!!", MB_OK ); continue; } if ( brush->pPatch ) { if ( bLoadPatches ) { DPatch* loadPatch = NewPatch(); loadPatch->LoadFromBrush_t( brush ); } } else { DBrush* loadBrush = NewBrush( i ); loadBrush->LoadFromBrush_t( brush, TRUE ); } } g_FuncTable.m_pfnReleaseEntityBrushHandles(); return TRUE; }
bool pre( scene::Node& node ) const { scene::Path path( NodeReference( GlobalSceneGraph().root() ) ); path.push( NodeReference( *m_entity->QER_Entity ) ); path.push( NodeReference( node ) ); scene::Instance* instance = GlobalSceneGraph().find( path ); ASSERT_MESSAGE( instance != 0, "" ); if ( Node_isPatch( node ) ) { DPatch* loadPatch = m_entity->NewPatch(); loadPatch->LoadFromPatch( *instance ); } else if ( Node_isBrush( node ) ) { DBrush* loadBrush = m_entity->NewBrush( m_count++ ); loadBrush->LoadFromBrush( *instance, true ); } return false; }
void DEntity::LoadSelectedPatches(){ ClearPatches(); ClearEPairs(); int count = g_FuncTable.m_pfnAllocateSelectedPatchHandles(); for ( int i = 0; i < count; i++ ) { //$ FIXME: m_pfnGetPatchHandle patchMesh_t *pmesh = (patchMesh_t*)g_FuncTable.m_pfnGetPatchData( i ); DPatch* loadPatch = NewPatch(); loadPatch->LoadFromBrush_t( pmesh->pSymbiot ); } g_FuncTable.m_pfnReleasePatchHandles(); }
DPatch* DPatch::MergePatches(patch_merge_t merge_info, DPatch *p1, DPatch *p2) { while(merge_info.pos1 != 2) { p1->Transpose(); merge_info.pos1--; if(merge_info.pos1 < 0) merge_info.pos1 += 4; } while(merge_info.pos2 != 0) { p2->Transpose(); merge_info.pos2--; if(merge_info.pos2 < 0) merge_info.pos2 += 3; } int newHeight = p1->height + p2->height - 1; if(newHeight > MAX_PATCH_HEIGHT) return NULL; DPatch* newPatch = new DPatch(); newPatch->height = newHeight; newPatch->width = p1->width; newPatch->SetTexture(p1->texture); int y = 0; int i; for(i = 0; i < p1->height; i++, y++) for(int x = 0; x < p1->width; x++) memcpy(&newPatch->points[x][y], &p1->points[x][i], sizeof(drawVert_t)); for(i = 1; i < p2->height; i++, y++) for(int x = 0; x < p2->width; x++) memcpy(&newPatch->points[x][y], &p2->points[x][i], sizeof(drawVert_t)); // newPatch->Invert(); return newPatch; }
DPatch* DPatch::MergePatches( patch_merge_t merge_info, DPatch *p1, DPatch *p2 ){ while ( merge_info.pos1 != 2 ) { p1->Transpose(); merge_info.pos1--; if ( merge_info.pos1 < 0 ) { merge_info.pos1 += 4; } } while ( merge_info.pos2 != 0 ) { p2->Transpose(); merge_info.pos2--; if ( merge_info.pos2 < 0 ) { merge_info.pos2 += 3; } } int newHeight = p1->height + p2->height - 1; if ( newHeight > MAX_PATCH_HEIGHT ) { return false; } DPatch* newPatch = new DPatch(); newPatch->height = newHeight; newPatch->width = p1->width; newPatch->SetTexture( p1->texture ); for ( int y = 0; y < p1->height; y++ ) for ( int x = 0; x < p1->width; x++ ) newPatch->points[x][y] = p1->points[x][y]; for ( int y = 1; y < p2->height; y++ ) for ( int x = 0; x < p2->width; x++ ) newPatch->points[x][( y + p1->height - 1 )] = p2->points[x][y]; // newPatch->Invert(); return newPatch; }
void DEntity_loadPatch( DEntity& entity, scene::Instance& patch ){ DPatch* loadPatch = entity.NewPatch(); loadPatch->LoadFromPatch( patch ); }
list<DPatch> DPatch::Split(bool rows, bool cols) { list<DPatch> patchList; int i; int x, y; if(rows && height >= 5) { for(i = 0; i < (height-1)/2; i++) { DPatch p; p.width = width; p.height = 3; p.SetTexture(texture); for(y = 0; y < 3; y++) { for(x = 0; x < p.width; x++) { memcpy(&p.points[x][y], &points[x][(i*2)+y], sizeof(drawVert_t)); } } patchList.push_back(p); } if(cols && width >= 5) { list<DPatch> patchList2; for(list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++) { list<DPatch> patchList3 = (*patches).Split(false, true); for(list<DPatch>::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++) patchList2.push_front(*patches2); } return patchList2; } } else if(cols && width >= 5) { for(i = 0; i < (width-1)/2; i++) { DPatch p; p.height = height; p.width = 3; p.SetTexture(texture); for(x = 0; x < 3; x++) { for(y = 0; y < p.height; y++) { memcpy(&p.points[x][y], &points[(i*2)+x][y], sizeof(drawVert_t)); } } patchList.push_back(p); } } return patchList; }
void DoMergePatches(){ patch_merge_t merge_info; DPatch mrgPatches[2]; int i; // ensure we have something selected if ( g_FuncTable.m_pfnSelectedBrushCount() != 2 ) { DoMessageBox( "Invalid number of objects selected, chose 2 only", "Error", MB_OK ); return; } g_FuncTable.m_pfnAllocateSelectedBrushHandles(); for ( i = 0; i < 2; i++ ) { brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle( i ); if ( !brush->pPatch ) { g_FuncTable.m_pfnReleaseSelectedBrushHandles(); DoMessageBox( "You must select ONLY patches", "Error", MB_OK ); return; } mrgPatches[i].LoadFromBrush_t( brush ); } /* mrgPatches[0].Transpose(); mrgPatches[0].RemoveFromRadiant(); mrgPatches[0].BuildInRadiant();*/ merge_info = mrgPatches[0].IsMergable( &mrgPatches[1] ); if ( merge_info.mergable ) { Sys_Printf( "%i %i", merge_info.pos1, merge_info.pos2 ); Sys_Printf( "Patches Mergable\n" ); DPatch* newPatch = mrgPatches[0].MergePatches( merge_info, &mrgPatches[0], &mrgPatches[1] ); /* mrgPatches[0].RemoveFromRadiant(); mrgPatches[0].BuildInRadiant(); mrgPatches[1].RemoveFromRadiant(); mrgPatches[1].BuildInRadiant(); delete newPatch;*/ if ( !newPatch ) { } else { mrgPatches[0].RemoveFromRadiant(); mrgPatches[1].RemoveFromRadiant(); newPatch->BuildInRadiant(); delete newPatch; } } g_FuncTable.m_pfnReleaseSelectedBrushHandles(); }