Raytracing API example/it: Difference between revisions

From FreeCAD Documentation
(Created page with "==Introduzione==")
(Updating to match new version of source page)
 
(9 intermediate revisions by 2 users not shown)
Line 2: Line 2:
==Introduzione==
==Introduzione==


The {{incode|Raytracing}} and {{incode|RaytracingGui}} modules provide several methods to write scene contents as povray or luxrender data.
I moduli {{incode|Raytracing}} e {{incode|RaytracingGui}} forniscono diversi metodi per scrivere i contenuti della scena come dati povray o luxrender.


The most useful commands are {{incode|Raytracing.getPartAsPovray()}} and {{incode|Raytracing.getPartAsLux()}} to render a FreeCAD Part object into a povray or luxrender definition, and {{incode|RaytracingGui.povViewCamera()}} and {{incode|RaytracinGui.luxViewCamera()}} to get the current point of view of the 3D view window into povray or luxrender format.
I comandi più utili sono {{incode|Raytracing.getPartAsPovray()}} e {{incode|Raytracing.getPartAsLux()}} per rendere un oggetto Part di FreeCAD in una definizione povray o luxrender e {{incode|RaytracingGui.povViewCamera( )}} e {{incode|RaytracinGui.luxViewCamera()}} per ottenere il punto di vista corrente della finestra della vista 3D in formato povray o luxrender.


== Emissione dei file di rendering ==
== Outputting render files ==


Ecco come utilizzare le funzionalità tramite Python, supponendo che il documento contenga un oggetto "Box":
Here is how to write a povray file from python, assuming your document contains a "Box" object:


{{Code|code=
{{Code|code=
Line 20: Line 20:
}}
}}


And the same for luxrender:
E la stessa cosa per luxrender:


{{Code|code=
{{Code|code=
Line 32: Line 32:
}}
}}


== Creating a custom render object ==
== Creare un oggetto render personalizzato ==
Apart from standard povray and luxrender view objects that provide a view of an existing Part object, and that can be inserted in povray and luxrender projects respectively, a third object exist, called RaySegment, that can be inserted either in povray or luxrender projects. That RaySegment object is not linked to any of the FreeCAD objects, and can contain custom povray or luxrender code, that you might wish to insert into your raytracing project. You can also use it, for example, to output your FreeCAD objects a certain way, if you are not happy with the standard way. You can create and use it like this from the python console:
Oltre agli oggetti di vista standard povray e luxrender che forniscono una vista di un oggetto Part esistente e che possono essere inseriti rispettivamente in progetti povray e luxrender, esiste un terzo oggetto, chiamato RaySegment, che può essere inserito in progetti povray o luxrender. L'oggetto RaySegment non è collegato ad alcuno degli oggetti di FreeCAD e può contenere del codice povray o luxrender personalizzato, che può essere inserito in un progetto raytracing. Ad esempio, può essere usato per generare gli oggetti di FreeCAD in un certo modo, se non si è soddisfatti del modo standard. Dalla console di Python può essere creato e usato in questo modo:


{{Code|code=
{{Code|code=
Line 42: Line 42:
}}
}}


{{Powerdocnavi{{#translation:}}}}
{{Raytracing Tools navi}}
[[Category:Developer Documentation{{#translation:}}]]
{{Userdocnavi}}
[[Category:API]]
[[Category:Python Code{{#translation:}}]]
{{Raytracing Tools navi{{#translation:}}}}
{{clear}}

Latest revision as of 21:09, 22 August 2020

Other languages:

Introduzione

I moduli Raytracing e RaytracingGui forniscono diversi metodi per scrivere i contenuti della scena come dati povray o luxrender.

I comandi più utili sono Raytracing.getPartAsPovray() e Raytracing.getPartAsLux() per rendere un oggetto Part di FreeCAD in una definizione povray o luxrender e RaytracingGui.povViewCamera( ) e RaytracinGui.luxViewCamera() per ottenere il punto di vista corrente della finestra della vista 3D in formato povray o luxrender.

Emissione dei file di rendering

Ecco come utilizzare le funzionalità tramite Python, supponendo che il documento contenga un oggetto "Box":

import Raytracing,RaytracingGui
OutFile = open('C:/Documents and Settings/jriegel/Desktop/test.pov','w')
OutFile.write(open(App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov').read())
OutFile.write(RaytracingGui.povViewCamera())
OutFile.write(Raytracing.getPartAsPovray('Box',App.activeDocument().Box.Shape,0.800000,0.800000,0.800000))
OutFile.close()
del OutFile

E la stessa cosa per luxrender:

import Raytracing,RaytracingGui
OutFile = open('C:/Documents and Settings/jriegel/Desktop/test.lxs','w')
OutFile.write(open(App.getResourceDir()+'Mod/Raytracing/Templates/LuxClassic.lxs').read())
OutFile.write(RaytracingGui.luxViewCamera())
OutFile.write(Raytracing.getPartAsLux('Box',App.activeDocument().Box.Shape,0.800000,0.800000,0.800000))
OutFile.close()
del OutFile

Creare un oggetto render personalizzato

Oltre agli oggetti di vista standard povray e luxrender che forniscono una vista di un oggetto Part esistente e che possono essere inseriti rispettivamente in progetti povray e luxrender, esiste un terzo oggetto, chiamato RaySegment, che può essere inserito in progetti povray o luxrender. L'oggetto RaySegment non è collegato ad alcuno degli oggetti di FreeCAD e può contenere del codice povray o luxrender personalizzato, che può essere inserito in un progetto raytracing. Ad esempio, può essere usato per generare gli oggetti di FreeCAD in un certo modo, se non si è soddisfatti del modo standard. Dalla console di Python può essere creato e usato in questo modo:

myRaytracingProject = FreeCAD.ActiveDocument.PovProject
myCustomRenderObject = FreeCAD.ActiveDocument.addObject("Raytracing::RaySegment","myRenderObject")
myRaytracingProject.addObject(myCustomRenderObject)
myCustomRenderObject.Result = "// Hello from python!"