From e3469ffd06efaf241b77e46cc12309b199e0370e Mon Sep 17 00:00:00 2001
From: Maurice Raybaud <mauriceraybaud@hotmail.fr>
Date: Sat, 31 Aug 2013 13:35:28 +0000
Subject: [PATCH] =?UTF-8?q?*Fixed=20one=20bug=20with=20multi-materials=20b?=
 =?UTF-8?q?earing=20custom=20pov=20code=20*Commented=20out=20a=20property?=
 =?UTF-8?q?=20that=20was=20not=20yet=20implemented=20in=20exporter=20*Adde?=
 =?UTF-8?q?d=20frame=20number=20export=20for=20hand=20made=20pov=20animati?=
 =?UTF-8?q?on=20Thanks=20to=20a=20patch=20made=20by=20Markku=20Myllym?=
 =?UTF-8?q?=C3=A4ki?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 render_povray/__init__.py | 12 ++++++------
 render_povray/render.py   | 22 +++++++++++++++-------
 render_povray/ui.py       | 20 ++++++++++----------
 3 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/render_povray/__init__.py b/render_povray/__init__.py
index 140e89695..16a1e5da7 100644
--- a/render_povray/__init__.py
+++ b/render_povray/__init__.py
@@ -411,12 +411,12 @@ class RenderPovSettingsTexture(PropertyGroup):
             min=0.45, max=5.00, soft_min=1.00, soft_max=2.50, default=1.00)
 
     ##################################CustomPOV Code############################
-    #Only DUMMIES below for now:
-    replacement_text = StringProperty(
-            name="Declared name:",
-            description="Type the declared name in custom POV code or an external .inc "
-                        "it points at. pigment {} expected",
-            default="")
+    #commented out below if we wanted custom pov code in texture only, inside exported material:
+    #replacement_text = StringProperty(
+    #        name="Declared name:",
+    #        description="Type the declared name in custom POV code or an external .inc "
+    #                    "it points at. pigment {} expected",
+    #        default="")
 
 
 ###############################################################################
diff --git a/render_povray/render.py b/render_povray/render.py
index ce660024a..f7c80d9a5 100644
--- a/render_povray/render.py
+++ b/render_povray/render.py
@@ -1252,6 +1252,10 @@ def write_pov(filename, scene=None, info_callback=None):
                                 file.write("\n #declare MAT_%s = \ntexture{\n" % currentMatName)
 
                                 ################################################################################
+                                
+                                if material.pov.replacement_text != "":
+                                    file.write("%s\n" % material.pov.replacement_text)
+                                #################################################################################
                                 if material.diffuse_shader == 'MINNAERT':
                                     tabWrite("\n")
                                     tabWrite("aoi\n")
@@ -1971,7 +1975,10 @@ def write_pov(filename, scene=None, info_callback=None):
         tabWrite("}\n")
 
     def exportCustomCode():
-
+        # Write CurrentAnimation Frame for use in Custom POV Code
+        file.write("#declare CURFRAMENUM = %d;\n" % bpy.context.scene.frame_current)
+        #Change path and uncomment to add an animated include file by hand:
+        file.write("//#include \"/home/user/directory/animation_include_file.inc\"\n")
         for txt in bpy.data.texts:
             if txt.pov.custom_code:
                 # Why are the newlines needed?
@@ -1988,16 +1995,17 @@ def write_pov(filename, scene=None, info_callback=None):
     file.write("#version 3.7;\n")
 
     if not scene.pov.tempfiles_enable and comments:
-        file.write("\n//--CUSTOM CODE--\n\n")
-    exportCustomCode()
-
-    if not scene.pov.tempfiles_enable and comments:
-        file.write("\n//--Global settings and background--\n\n")
+        file.write("\n//--Global settings--\n\n")
 
     exportGlobalSettings(scene)
 
+    
     if not scene.pov.tempfiles_enable and comments:
-        file.write("\n")
+        file.write("\n//--Custom Code--\n\n")
+    exportCustomCode()
+    
+    if not scene.pov.tempfiles_enable and comments:
+        file.write("\n//--Background--\n\n")
 
     exportWorld(scene.world)
 
diff --git a/render_povray/ui.py b/render_povray/ui.py
index d53f28041..7334909c4 100644
--- a/render_povray/ui.py
+++ b/render_povray/ui.py
@@ -518,19 +518,19 @@ class TEXTURE_PT_povray_tex_gamma(TextureButtonsPanel, bpy.types.Panel):
         layout.active = tex.pov.tex_gamma_enable
         layout.prop(tex.pov, "tex_gamma_value", text="Gamma Value")
 
+#commented out below UI for texture only custom code inside exported material:
+# class TEXTURE_PT_povray_replacement_text(TextureButtonsPanel, bpy.types.Panel):
+    # bl_label = "Custom POV Code"
+    # COMPAT_ENGINES = {'POVRAY_RENDER'}
 
-class TEXTURE_PT_povray_replacement_text(TextureButtonsPanel, bpy.types.Panel):
-    bl_label = "Custom POV Code"
-    COMPAT_ENGINES = {'POVRAY_RENDER'}
-
-    def draw(self, context):
-        layout = self.layout
+    # def draw(self, context):
+        # layout = self.layout
 
-        tex = context.texture
+        # tex = context.texture
 
-        col = layout.column()
-        col.label(text="Replace properties with:")
-        col.prop(tex.pov, "replacement_text", text="")
+        # col = layout.column()
+        # col.label(text="Replace properties with:")
+        # col.prop(tex.pov, "replacement_text", text="")
 
 
 class OBJECT_PT_povray_obj_importance(ObjectButtonsPanel, bpy.types.Panel):
-- 
GitLab