/*************************************************************************** * Copyright (c) 2005 Jürgen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ # include # include # include # include # include # include # include # include # include #endif #include #include #include #include #include #include #include "PovTools.h" #include "LuxTools.h" using Base::Console; using namespace Raytracing; using namespace std; std::string LuxTools::getCamera(const CamDef& Cam) { std::stringstream out; out << "# declares position and view direction" << endl << "# Generated by FreeCAD (http://www.freecadweb.org/)" << endl // writing Camera positions << "LookAt " << Cam.CamPos.X() << " " << Cam.CamPos.Y() << " " << Cam.CamPos.Z() << " " // writing lookat << Cam.LookAt.X() << " " << Cam.LookAt.Y() << " " << Cam.LookAt.Z() << " " // writing the Up Vector << Cam.Up.X() << " " << Cam.Up.Y() << " " << Cam.Up.Z() << endl; return out.str(); } void LuxTools::writeShape(std::ostream &out, const char *PartName, const TopoDS_Shape& Shape, float fMeshDeviation) { Base::Console().Log("Meshing with Deviation: %f\n",fMeshDeviation); TopExp_Explorer ex; BRepMesh_IncrementalMesh MESH(Shape,fMeshDeviation); // counting faces and start sequencer int l = 1; for (ex.Init(Shape, TopAbs_FACE); ex.More(); ex.Next(),l++) {} Base::SequencerLauncher seq("Writing file", l); // write object out << "AttributeBegin # \"" << PartName << "\"" << endl; out << "Transform [1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1]" << endl; out << "NamedMaterial \"FreeCADMaterial_" << PartName << "\"" << endl; out << "Shape \"mesh\"" << endl; // gather vertices, normals and face indices std::stringstream triindices; std::stringstream N; std::stringstream P; l = 1; int vi = 0; for (ex.Init(Shape, TopAbs_FACE); ex.More(); ex.Next(),l++) { // get the shape and mesh it const TopoDS_Face& aFace = TopoDS::Face(ex.Current()); // this block mesh the face and transfers it in a C array of vertices and face indexes Standard_Integer nbNodesInFace,nbTriInFace; gp_Vec* vertices=0; gp_Vec* vertexnormals=0; long* cons=0; PovTools::transferToArray(aFace,&vertices,&vertexnormals,&cons,nbNodesInFace,nbTriInFace); if (!vertices) break; // writing vertices for (int i=0; i < nbNodesInFace; i++) { P << vertices[i].X() << " " << vertices[i].Y() << " " << vertices[i].Z() << " "; } // writing per vertex normals for (int j=0; j < nbNodesInFace; j++) { N << vertexnormals[j].X() << " " << vertexnormals[j].Y() << " " << vertexnormals[j].Z() << " "; } // writing triangle indices for (int k=0; k < nbTriInFace; k++) { triindices << cons[3*k]+vi << " " << cons[3*k+2]+vi << " " << cons[3*k+1]+vi << " "; } vi = vi + nbNodesInFace; delete [] vertexnormals; delete [] vertices; delete [] cons; seq.next(); } // end of face loop // write mesh data out << " \"integer triindices\" [" << triindices.str() << "]" << endl; out << " \"point P\" [" << P.str() << "]" << endl; out << " \"normal N\" [" << N.str() << "]" << endl; out << " \"bool generatetangents\" [\"false\"]" << endl; out << " \"string name\" [\"" << PartName << "\"]" << endl; out << "AttributeEnd # \"\"" << endl; }