Macro FreeCAD to Kerkythea
{{Macro |Name=FC to Kerkythea |Icon=Macro_FreeCAD_to_Kerkythea.png |Description=Macro to export your model to the raytracing program [http://www.kerkythea.net/cms/ Kerkythea]. |Author=marmni |Version=1.0 |Date=2015-05-30 |FCVersion=0.17 and above |Download=[https://www.freecadweb.org/wiki/https://raw.githubusercontent.com/FreeCAD/FreeCAD-documentation/master/wiki/images/8/8c/Macro_FreeCAD_to_Kerkythea.png ToolBar Icon] }}
Description
Macro to export your model to the raytracing program Kerkythea.
Usage
The macro you can find in the following github repository: FreeCAD to Kerkythea-Exporter
It is pretty self-explanatory. At the moment there are problems with exporting lights and the camera position.
Link
The page discussion Kerkythea Rendering System
Script
ToolBar Icon
Macro ExportToKerkythea.py
{{MacroCode|code=
-- coding: utf8 --
**
Kerkythea exporter
Copyright (c) 2014,2015
marmni marmni@onet.eu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL)
as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
for detail see the LICENCE text file.
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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
**
**
BASED ON
IOANNIS PANTAZOPOULOS
Sample code exporting basic Kerkythea XML file.
Version v1.0
**
title="Kerkythea exporter" author = "marmni marmni@onet.eu" url = ["http://www.freecadweb.org"]
import FreeCAD, FreeCADGui import re import random import builtin import Mesh from PySide import QtCore, QtGui import sys import os
##############################################
############################################## class point3D: def init(self, point): self.x = "%.4f" % (point[0] 0.001) self.y = "%.4f" % (point[1] 0.001) self.z = "%.4f" % (point[2] * 0.001)
def __str__(self):
return '<P xyz="{0} {1} {2}"/>'.format(self.x, self.y, self.z)
#def __eq__(self, other):
#if self.x == other.x and self.y == other.y and self.z == other.z:
#return True
#else:
#return False
##############################################
############################################## class indexListPoint3D: def init(self, point): self.i = point[0] self.j = point[1] self.k = point[2]
def __str__(self):
return '<F ijk="{0} {1} {2}"/>'.format(self.i, self.j, self.k)
##############################################
############################################## class Material: def init(self): self.diffuse = None # Texture() self.shininess = 1000.0 self.ior = 2.0
def write(self, file):
file.write('''<Object Identifier="Whitted Material" Label="Whitted Material" Name="" Type="Material">\n''')
self.diffuse.write(file, "Diffuse")
self.diffuse.write(file, "Translucent")
self.diffuse.write(file, "Specular")
self.diffuse.write(file, "Transmitted")
file.write('''<Parameter Name="Shininess" Type="Real" Value="{shininess}"/>
##############################################
############################################## class Texture: def init(self, color): self.color = color
def getColorSTR(self):
return '{0} {1} {2}'.format(self.color[0], self.color[1], self.color[2])
def toGrayscale(self):
RGB = 0.299 * self.color[0] + 0.587 * self.color[1] + 0.114 * self.color[2]
self.color = [RGB, RGB, RGB]
def write(self, file, identifier):
file.write('''<Object Identifier="./{identifier}/Constant Texture" Label="Constant Texture" Name="" Type="Texture">
##############################################
############################################## class Model: def init(self): self.vertexList = [] self.normalList = [] self.indexList = []
self.name = self.wygenerujID(5, 5)
self.material = Material()
def addFace(self, face):
mesh = self.meshFace(face)
for pp in mesh.Facets:
num = len(self.vertexList)
for kk in pp.Points:
self.vertexList.append(point3D(kk))
self.indexList.append(indexListPoint3D([num, num + 1, num + 2]))
def meshFace(self, shape):
faces = []
triangles = shape.tessellate(1) # the number represents the precision of the tessellation
for tri in triangles[1]:
face = []
for i in range(3):
vindex = tri[i]
face.append(triangles[0][vindex])
faces.append(face)
m = Mesh.Mesh(faces)
#Mesh.show(m)
return m
def wygenerujID(self, ll, lc):
''' generate random model name '''
numerID = ""
for i in range(ll):
numerID += random.choice('abcdefghij')
numerID += "_"
for i in range(lc):
numerID += str(random.randrange(0, 99, 1))
return numerID
def write(self, file):
file.write('''