brush_t *BrushFromMapPatch(idMapPatch *mappatch, idVec3 origin) { patchMesh_t *pm = MakeNewPatch(mappatch->GetWidth(), mappatch->GetHeight()); pm->d_texture = Texture_ForName(mappatch->GetMaterial()); for (int i = 0; i < mappatch->GetWidth(); i++) { for (int j = 0; j < mappatch->GetHeight(); j++) { pm->ctrl(i, j).xyz = (*mappatch)[j * mappatch->GetWidth() + i].xyz + origin; pm->ctrl(i, j).st = (*mappatch)[j * mappatch->GetWidth() + i].st; } } pm->horzSubdivisions = mappatch->GetHorzSubdivisions(); pm->vertSubdivisions = mappatch->GetVertSubdivisions(); pm->explicitSubdivisions = mappatch->GetExplicitlySubdivided(); if (mappatch->epairs.GetNumKeyVals()) { pm->epairs = new idDict; *pm->epairs = mappatch->epairs; } brush_t *b = AddBrushForPatch(pm, false); return b; }
void CPlugInManager::CommitPatchHandleToMap(int index, patchMesh_t *pMesh, char *texName) { if (PatchesMode==EAllocatedPatches) { patchMesh_t *pPatch = reinterpret_cast<patchMesh_t *>( m_PluginPatches.GetAt(index) ); memcpy( pPatch, pMesh, sizeof( patchMesh_t ) ); // patch texturing, if none given use current texture if (texName) pPatch->d_texture = Texture_ForName(texName); if ( !pPatch->d_texture ) { pPatch->d_texture = Texture_ForName(g_qeglobals.d_texturewin.texdef.name); // checking .. just in case if (!pPatch->d_texture) { #ifdef _DEBUG Sys_Printf("WARNING: failed to set patch to current texture in CPlugInManager::CommitPatchHandleToMap\n"); #endif pPatch->d_texture = notexture; } } g_bScreenUpdates = false; // the bLinkToWorld flag in AddBrushForPatch takes care of Brush_AddToList Entity_linkBrush and Brush_Build brush_t *pb = AddBrushForPatch( pPatch, true ); Select_Brush( pb ); g_bScreenUpdates = true; Sys_UpdateWindows(W_ALL); } else { brush_t *pBrush = reinterpret_cast<brush_t *>( m_PatchesHandles.GetAt(index) ); patchMesh_t *pPatch = pBrush->pPatch; pPatch->width = pMesh->width; pPatch->height = pMesh->height; pPatch->contents = pMesh->contents; pPatch->flags = pMesh->flags; pPatch->value = pMesh->value; pPatch->type = pMesh->type; memcpy( pPatch->ctrl, pMesh->ctrl, sizeof(drawVert_t)*MAX_PATCH_HEIGHT*MAX_PATCH_WIDTH ); pPatch->bDirty = true; } }