From c9442833d966f60aa9587d809e7d60b3cdcfc10b Mon Sep 17 00:00:00 2001
From: Jared Sampson <jared.sampson@gmail.com>
Date: Thu, 24 Mar 2016 19:07:58 -0400
Subject: [PATCH] Add collada_background_box setting (default=0).

By default COLLADA output will not contain the background box, but it can be enabled by setting to 1.  This setting is overridden by geometry_export_mode==1, as none of the scene information (including the background box) will be included.
---
 ChangeLog            |  5 +++++
 layer1/COLLADA.cpp   | 15 +++++++++++++--
 layer1/SettingInfo.h |  1 +
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 007b7ae..24a2ce5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,11 @@
 CHANGE LOG
 =========================================================================
 
+2016-03-24 Jared Sampson
+
+	* new setting: collada_background_box (default 0)
+		https://sourceforge.net/p/pymol/mailman/message/34961984/
+
 2016-03-21 Thomas Holder, Gabriel Marques
 
 	* pse_export_version: save 1.7.6 compatible PSEs by default
diff --git a/layer1/COLLADA.cpp b/layer1/COLLADA.cpp
index da10c30..9d14679 100644
--- a/layer1/COLLADA.cpp
+++ b/layer1/COLLADA.cpp
@@ -701,6 +701,16 @@ void RayRenderCOLLADA(CRay * I, int width, int height,
   int identity = (SettingGetGlobal_i(I->G, cSetting_geometry_export_mode) == 1);
 
   /*
+   * Setting: collada_background_box
+   * -------------------------------
+   * 0 = Do not include a background box. (default)
+   * 1 = Include the background box for more accurate reproduction of the scene.
+   * NB: This setting is overridden by geometry_export_mode == 1, in which case
+   * no background box will be generated.
+   */
+  int bgbox = SettingGetGlobal_i(I->G, cSetting_collada_background_box);
+
+  /*
    * Setting: collada_geometry_mode
    * ------------------------------
    * 0 = Valid COLLADA 1.4.1. (default)
@@ -915,7 +925,8 @@ void RayRenderCOLLADA(CRay * I, int width, int height,
            */
 
           /* Generate bounding box geometry for background. */
-          if (!identity) {
+          /* Only if collada_background_box == 1 and geometry_export_mode == 0 */
+          if (!identity && bgbox) {
             /* Ensure camera is inside bounding box */
             int i;
             for (i = 0; i < 3; i++) {
@@ -1686,7 +1697,7 @@ void RayRenderCOLLADA(CRay * I, int width, int height,
     free(mat);
 
     /* background geometry */
-    if (!identity) {
+    if (!identity && bgbox) {
       xmlTextWriterStartElement(w, BAD_CAST "node");
       xmlTextWriterWriteAttribute(w, BAD_CAST "id", BAD_CAST "node-geom-bg");
 
diff --git a/layer1/SettingInfo.h b/layer1/SettingInfo.h
index ec3392b..3dff944 100644
--- a/layer1/SettingInfo.h
+++ b/layer1/SettingInfo.h
@@ -860,6 +860,7 @@ enum {
   REC_f( 752, valence_zero_scale                      , ostate    , 0.2f ),
   REC_i( 753, valence_zero_mode                       , ostate    , 1, 0, 2 ), // 0: skip, 1: dashed, 2: solid
   REC_i( 754, auto_show_classified                    , global    , 0, 0, 3 ), // 0: off, 1: as, 2: show, 3: simple
+  REC_i( 755, collada_background_box                  , global    , 0, 0, 1 ), // 0: off, 1: on
 
 #ifdef SETTINGINFO_IMPLEMENTATION
 #undef SETTINGINFO_IMPLEMENTATION
-- 
2.4.9 (Apple Git-60)

