/* Copyright (c) 2002-2012 Croteam Ltd. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "stdh.h" #include #include #include #include #include #include #include /* * Fill a 3d object from a selection in a brush mip. */ void CBrushMip::ToObject3D( CObject3D &ob, CBrushSectorSelection &selbscToCopy) { ASSERT(GetFPUPrecision()==FPT_53BIT); // get number of sectors in the selection INDEX ctSectors = selbscToCopy.Count(); // create that much sectors in the object CObjectSector *poscSectors = ob.ob_aoscSectors.New(ctSectors); // for each sector in the selection mip FOREACHINDYNAMICCONTAINER(selbscToCopy, CBrushSector, itbsc) { // fill corresponding sector in object from it itbsc->ToObjectSector(*poscSectors++); } // optimize the object, to remove unused elements // CBrush3D::OptimizeObject3D(ob); } /* * Fill a 3d object from a selection in a brush mip. */ void CBrushMip::ToObject3D( CObject3D &ob, CBrushSectorSelectionForCSG &selbscToCopy) { CSetFPUPrecision sfp(FPT_53BIT); // get number of sectors in the selection INDEX ctSectors = selbscToCopy.Count(); // create that much sectors in the object CObjectSector *poscSectors = ob.ob_aoscSectors.New(ctSectors); // for each sector in the selection mip FOREACHINDYNAMICCONTAINER(selbscToCopy, CBrushSector, itbsc) { // fill corresponding sector in object from it itbsc->ToObjectSector(*poscSectors++); } // optimize the object, to remove unused elements // CBrush3D::OptimizeObject3D(ob); } /* * Fill an object sector from a sector in brush. */ void CBrushSector::ToObjectSector(CObjectSector &osc) { // copy sector color and ambient osc.osc_colColor = bsc_colColor; osc.osc_colAmbient = bsc_colAmbient; osc.osc_ulFlags[0] = bsc_ulFlags; osc.osc_ulFlags[1] = bsc_ulFlags2; osc.osc_ulFlags[2] = bsc_ulVisFlags; osc.osc_strName = bsc_strName; // lock the object elements osc.LockAll(); // lock the brush elements LockAll(); /* Copy vertices. */ // get the number of vertices in brush INDEX ctVertices = bsc_abvxVertices.Count(); // create that much vertices in object osc.osc_aovxVertices.New(ctVertices); // copy all vertices for(INDEX iVertex=0; iVertex=sizePolygonProperties+3*sizeTextureProperties); UBYTE *pubUserData = (UBYTE*)&opo.opo_ubUserData; memcpy(pubUserData, &bpo.bpo_bppProperties, sizePolygonProperties); memcpy(pubUserData+sizePolygonProperties+0*sizeTextureProperties, &bpo.bpo_abptTextures[0].bpt_auProperties, sizeTextureProperties); memcpy(pubUserData+sizePolygonProperties+1*sizeTextureProperties, &bpo.bpo_abptTextures[1].bpt_auProperties, sizeTextureProperties); memcpy(pubUserData+sizePolygonProperties+2*sizeTextureProperties, &bpo.bpo_abptTextures[2].bpt_auProperties, sizeTextureProperties); *(ULONG*)(pubUserData+sizePolygonProperties+3*sizeTextureProperties) = bpo.bpo_colShadow; opo.opo_PolygonEdges.Lock(); // get the number of edges in brush polygon INDEX ctPolygonEdges = bpo.bpo_abpePolygonEdges.Count(); // create that much edges in object polygon opo.opo_PolygonEdges.New(ctPolygonEdges); // for all edges in brush polygon INDEX iPolygonEdge=0; FOREACHINSTATICARRAY(bpo.bpo_abpePolygonEdges, CBrushPolygonEdge, itbpe) { // get corresponding polygon edge in object polygon CObjectPolygonEdge &ope = opo.opo_PolygonEdges[iPolygonEdge]; // set edge reference ope.ope_Edge = &osc.osc_aoedEdges[bsc_abedEdges.Index(itbpe->bpe_pbedEdge)]; // set backward flag ope.ope_Backward = itbpe->bpe_bReverse; iPolygonEdge++; } opo.opo_PolygonEdges.Unlock(); } // unlock the object elements osc.UnlockAll(); // unlock the brush elements UnlockAll(); }