| 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * Further, this software is distributed without any warranty that it is |
| 16 | * free of the rightful claim of any third person regarding infringement |
| 17 | * or the like. Any license provided herein, whether implied or |
| 18 | * otherwise, applies only to this software file. Patent licenses, if |
| 19 | * any, provided herein do not apply to combinations of this program with |
| 20 | * other software, or any other product whatsoever. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 | * Mountain View, CA 94043, or: |
| 28 | * |
| 29 | * http://www.sgi.com |
| 30 | * |
| 31 | * For further information regarding this notice, see: |
| 32 | * |
| 33 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | #include <Inventor/actions/SoSearchAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoSearchAction.h`/ |
| 38 | #include <Inventor/elements/SoLazyElement.h>cxx . . $ `<file>/lib/database/include/Inventor/elements/SoLazyElement.h`/ |
| 39 | #include <Inventor/nodes/SoBaseColor.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoBaseColor.h`/ |
| 40 | #include <Inventor/nodes/SoGroup.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoGroup.h`/ |
| 41 | #include <Inventor/nodes/SoMaterial.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoMaterial.h`/ |
| 42 | #include <Inventor/nodes/SoPackedColor.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoPackedColor.h`/ |
| 43 | |
| 44 | #include "IfAssert.h"cxx . . $ `<file>/apps/tools/ivfix/IfAssert.h`/ |
| 45 | #include "IfReplacer.h"cxx . . $ `<file>/apps/tools/ivfix/IfReplacer.h`/ |
| 46 | |
| 47 | ///////////////////////////////////////////////////////////////////////////// |
| 48 | // |
| 49 | // Constructor. |
| 50 | // |
| 51 | ///////////////////////////////////////////////////////////////////////////// |
| 52 | |
| 53 | IfReplacercxx . . $ IfReplacer#::IfReplacercxx . . $ IfReplacer#IfReplacer(49f6e7a06ebc5aa8).() |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | ///////////////////////////////////////////////////////////////////////////// |
| 58 | // |
| 59 | // Destructor. |
| 60 | // |
| 61 | ///////////////////////////////////////////////////////////////////////////// |
| 62 | |
| 63 | IfReplacercxx . . $ IfReplacer#::~cxx . . $ IfReplacer#`~IfReplacer`(49f6e7a06ebc5aa8).IfReplacercxx . . $ IfReplacer#() |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | ///////////////////////////////////////////////////////////////////////////// |
| 68 | // |
| 69 | // Replaces nodes in the given scene, in place. |
| 70 | // |
| 71 | ///////////////////////////////////////////////////////////////////////////// |
| 72 | |
| 73 | void |
| 74 | IfReplacercxx . . $ IfReplacer#::replacecxx . . $ IfReplacer#replace(da6c7544ccee32bd).(SoNodecxx . . $ SoNode# *sceneRoot) |
| 75 | { |
| 76 | // Replace all SoBaseColor and SoPackedColor nodes with SoMaterial |
| 77 | // nodes, which are easier to deal with |
| 78 | replaceMaterialscxx . . $ IfReplacer#replaceMaterials(da33852fcbe6d361).(sceneRoot, SoBaseColorcxx . . $ SoBaseColor#::getClassTypeIdcxx . . $ SoBaseColor#getClassTypeId(c00c150378d2b968).()); |
| 79 | replaceMaterialscxx . . $ IfReplacer#replaceMaterials(da33852fcbe6d361).(sceneRoot, SoPackedColorcxx . . $ SoPackedColor#::getClassTypeIdcxx . . $ SoPackedColor#getClassTypeId(c00c150378d2b968).()); |
| 80 | } |
| 81 | |
| 82 | ///////////////////////////////////////////////////////////////////////////// |
| 83 | // |
| 84 | // Replaces all nodes of the given type with SoMaterial nodes. |
| 85 | // |
| 86 | ///////////////////////////////////////////////////////////////////////////// |
| 87 | |
| 88 | void |
| 89 | IfReplacercxx . . $ IfReplacer#::replaceMaterialscxx . . $ IfReplacer#replaceMaterials(da33852fcbe6d361).(SoNodecxx . . $ SoNode# *sceneRoot, const SoTypecxx . . $ SoType# &typeToReplace) |
| 90 | { |
| 91 | // Find all nodes of the given type |
| 92 | SoSearchActioncxx . . $ SoSearchAction# sacxx . . $ SoSearchAction#SoSearchAction(49f6e7a06ebc5aa8).; |
| 93 | sa.setTypecxx . . $ SoSearchAction#setType(a368ce5ca5a50910).(typeToReplace); |
| 94 | sa.setInterestcxx . . $ SoSearchAction#setInterest(b27440939ca13a5b).(SoSearchActioncxx . . $ SoSearchAction#::ALLcxx . . $ SoSearchAction#ALL.); |
| 95 | sa.applycxx . . $ SoAction#apply(da6c7544ccee32bd).(sceneRoot); |
| 96 | |
| 97 | // Replace the tail of each path with a material. To do this, we |
| 98 | // need to apply an SoCallbackAction to the path to gather the |
| 99 | // material components. |
| 100 | for (int i = 0; i < sa.getPathscxx . . $ SoSearchAction#getPaths(e5198181f61c9f38).().getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).(); i++) { |
| 101 | |
| 102 | // Cast the path to a full path, just in case |
| 103 | SoFullPathcxx . . $ SoFullPath# *path = (SoFullPathcxx . . $ SoFullPath# *) sa.getPathscxx . . $ SoSearchAction#getPaths(e5198181f61c9f38).()[cxx . . $ SoPathList#`operator[]`(81b2b9099fcfac9c).i]; |
| 104 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(path->getTail()->isOfType(typeToReplace)); |
| 105 | |
| 106 | // The path better have at least one group above the material |
| 107 | if (path->getLengthcxx . . $ SoFullPath#getLength(455f465bc33b4cdf).() < 2 || |
| 108 | ! path->getNodeFromTailcxx . . $ SoFullPath#getNodeFromTail(fd675789997d09c2).(1)->isOfTypecxx . . $ SoBase#isOfType(1fd66475a268b64e).(SoGroupcxx . . $ SoGroup#::getClassTypeIdcxx . . $ SoGroup#getClassTypeId(c00c150378d2b968).())) |
| 109 | continue; |
| 110 | |
| 111 | // Create a material node that represents the material in |
| 112 | // effect at the tail of the path |
| 113 | SoMaterialcxx . . $ SoMaterial# *newMaterial = createMaterialForPathcxx . . $ IfReplacer#createMaterialForPath(dee5eb8db0ba8291).(path); |
| 114 | newMaterial->refcxx . . $ SoBase#ref(83f5f38750778ac8).(); |
| 115 | |
| 116 | // Replace the tail node with that material |
| 117 | SoGroupcxx . . $ SoGroup# *parent = (SoGroupcxx . . $ SoGroup# *) path->getNodeFromTailcxx . . $ SoFullPath#getNodeFromTail(fd675789997d09c2).(1); |
| 118 | parent->replaceChildcxx . . $ SoGroup#replaceChild(c33fb305120b01c8).(path->getTailcxx . . $ SoFullPath#getTail(b794963b450d51b3).(), newMaterial); |
| 119 | |
| 120 | newMaterial->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).(); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | ///////////////////////////////////////////////////////////////////////////// |
| 125 | // |
| 126 | // Creates and returns a material node that represents the material in |
| 127 | // effect at the tail of the given path. |
| 128 | // |
| 129 | ///////////////////////////////////////////////////////////////////////////// |
| 130 | |
| 131 | SoMaterialcxx . . $ SoMaterial# * |
| 132 | IfReplacercxx . . $ IfReplacer#::createMaterialForPathcxx . . $ IfReplacer#createMaterialForPath(dee5eb8db0ba8291).(SoPathcxx . . $ SoPath# *path) |
| 133 | { |
| 134 | materialcxx . . $ IfReplacer#material. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 135 | |
| 136 | // Apply an SoCallbackAction to the path, and create the material |
| 137 | // after we get to the tail node |
| 138 | SoCallbackActioncxx . . $ SoCallbackAction# cbacxx . . $ SoCallbackAction#SoCallbackAction(49f6e7a06ebc5aa8).; |
| 139 | cba.addPostTailCallbackcxx . . $ SoCallbackAction#addPostTailCallback(44a3ba4006a23a06).(materialTailCBcxx . . $ IfReplacer#materialTailCB(6eea413111466577)., this); |
| 140 | cba.applycxx . . $ SoAction#apply(eed4dbbaf0eca0f1).(path); |
| 141 | |
| 142 | ASSERTcxx . . $ `apps/tools/ivfix/IfAssert.h:54:9`!(material != NULL); |
| 143 | |
| 144 | return materialcxx . . $ IfReplacer#material.; |
| 145 | } |
| 146 | |
| 147 | ///////////////////////////////////////////////////////////////////////////// |
| 148 | // |
| 149 | // Stores a material created during traversal of a path. |
| 150 | // |
| 151 | ///////////////////////////////////////////////////////////////////////////// |
| 152 | |
| 153 | void |
| 154 | IfReplacercxx . . $ IfReplacer#::storeMaterialcxx . . $ IfReplacer#storeMaterial(425635c2081b81c8).(SoCallbackActioncxx . . $ SoCallbackAction# *cba) |
| 155 | { |
| 156 | // Create a new material |
| 157 | materialcxx . . $ IfReplacer#material. = new SoMaterialcxx . . $ SoMaterial#; |
| 158 | |
| 159 | // Copy the values from the elements in the state into the |
| 160 | |
| 161 | SoStatecxx . . $ SoState# *state = cba->getStatecxx . . $ SoAction#getState(5c8eb8fe6550a03).(); |
| 162 | SoLazyElementcxx . . $ SoLazyElement# *elt = SoLazyElementcxx . . $ SoLazyElement#::getInstancecxx . . $ SoLazyElement#getInstance(c3f42909ceeb206f).(cba->getStatecxx . . $ SoAction#getState(5c8eb8fe6550a03).()); |
| 163 | |
| 164 | // Most values can have only one value |
| 165 | materialcxx . . $ IfReplacer#material.->ambientColorcxx . . $ SoMaterial#ambientColor. =cxx . . $ SoMFColor#`operator=`(3bd68adc21d5b146). SoLazyElementcxx . . $ SoLazyElement#::getAmbientcxx . . $ SoLazyElement#getAmbient(5185631f02741b1b).(state); |
| 166 | materialcxx . . $ IfReplacer#material.->specularColorcxx . . $ SoMaterial#specularColor. =cxx . . $ SoMFColor#`operator=`(3bd68adc21d5b146). SoLazyElementcxx . . $ SoLazyElement#::getSpecularcxx . . $ SoLazyElement#getSpecular(5185631f02741b1b).(state); |
| 167 | materialcxx . . $ IfReplacer#material.->emissiveColorcxx . . $ SoMaterial#emissiveColor. =cxx . . $ SoMFColor#`operator=`(3bd68adc21d5b146). SoLazyElementcxx . . $ SoLazyElement#::getEmissivecxx . . $ SoLazyElement#getEmissive(5185631f02741b1b).(state); |
| 168 | materialcxx . . $ IfReplacer#material.->shininesscxx . . $ SoMaterial#shininess. =cxx . . $ SoMFFloat#`operator=`(fbcf3211dfe1bfd1). SoLazyElementcxx . . $ SoLazyElement#::getShininesscxx . . $ SoLazyElement#getShininess(ac74db52455d3e23).(state); |
| 169 | |
| 170 | // If the element contains packed colors, unpack each one into a |
| 171 | // diffuse color and a transparency value. If they are not packed, |
| 172 | // set the diffuse colors and transparency values separately. |
| 173 | |
| 174 | if (elt->isPackedcxx . . $ SoLazyElement#isPacked(455f465bc33b4cdf).()) { |
| 175 | int num = elt->getNumDiffusecxx . . $ SoLazyElement#getNumDiffuse(455f465bc33b4cdf).(); |
| 176 | materialcxx . . $ IfReplacer#material.->diffuseColorcxx . . $ SoMaterial#diffuseColor..setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(num); |
| 177 | materialcxx . . $ IfReplacer#material.->transparencycxx . . $ SoMaterial#transparency..setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(num); |
| 178 | SbColorcxx . . $ SbColor# *colors = materialcxx . . $ IfReplacer#material.->diffuseColorcxx . . $ SoMaterial#diffuseColor..startEditingcxx . . $ SoMFColor#startEditing(bb43ce3e427ef7d0).(); |
| 179 | float *trans = materialcxx . . $ IfReplacer#material.->transparencycxx . . $ SoMaterial#transparency..startEditingcxx . . $ SoMFFloat#startEditing(a3aba87f01dec7c2).(); |
| 180 | const uint32_tcxx . . $ uint32_t# *eltPacked = elt->getPackedPointercxx . . $ SoLazyElement#getPackedPointer(a41a679bfd47d521).(); |
| 181 | for (int i = 0; i < num; i++) |
| 182 | colors[i].setPackedValuecxx . . $ SbColor#setPackedValue(e2bedabf26994b1f).(eltPacked[i], trans[i]); |
| 183 | materialcxx . . $ IfReplacer#material.->diffuseColorcxx . . $ SoMaterial#diffuseColor..finishEditingcxx . . $ SoMFColor#finishEditing(49f6e7a06ebc5aa8).(); |
| 184 | materialcxx . . $ IfReplacer#material.->transparencycxx . . $ SoMaterial#transparency..finishEditingcxx . . $ SoMFFloat#finishEditing(49f6e7a06ebc5aa8).(); |
| 185 | } |
| 186 | |
| 187 | else { |
| 188 | int i, num = elt->getNumDiffusecxx . . $ SoLazyElement#getNumDiffuse(455f465bc33b4cdf).(); |
| 189 | materialcxx . . $ IfReplacer#material.->diffuseColorcxx . . $ SoMaterial#diffuseColor..setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(num); |
| 190 | SbColorcxx . . $ SbColor# *colors = materialcxx . . $ IfReplacer#material.->diffuseColorcxx . . $ SoMaterial#diffuseColor..startEditingcxx . . $ SoMFColor#startEditing(bb43ce3e427ef7d0).(); |
| 191 | const SbColorcxx . . $ SbColor# *eltColors = elt->getDiffusePointercxx . . $ SoLazyElement#getDiffusePointer(2e9402095e14a193).(); |
| 192 | for (i = 0; i < num; i++) |
| 193 | colors[i] =cxx . . $ SbColor#`operator=`(44a021c60a83616a). eltColors[i]; |
| 194 | materialcxx . . $ IfReplacer#material.->diffuseColorcxx . . $ SoMaterial#diffuseColor..finishEditingcxx . . $ SoMFColor#finishEditing(49f6e7a06ebc5aa8).(); |
| 195 | |
| 196 | num = elt->getNumTransparenciescxx . . $ SoLazyElement#getNumTransparencies(455f465bc33b4cdf).(); |
| 197 | materialcxx . . $ IfReplacer#material.->transparencycxx . . $ SoMaterial#transparency..setNumcxx . . $ SoMField#setNum(d4f767463ce0a6b3).(num); |
| 198 | float *trans = materialcxx . . $ IfReplacer#material.->transparencycxx . . $ SoMaterial#transparency..startEditingcxx . . $ SoMFFloat#startEditing(a3aba87f01dec7c2).(); |
| 199 | const float *eltTrans = elt->getTransparencyPointercxx . . $ SoLazyElement#getTransparencyPointer(d64004c6a662f6a6).(); |
| 200 | for (i = 0; i < num; i++) |
| 201 | trans[i] = eltTrans[i]; |
| 202 | materialcxx . . $ IfReplacer#material.->transparencycxx . . $ SoMaterial#transparency..finishEditingcxx . . $ SoMFFloat#finishEditing(49f6e7a06ebc5aa8).(); |
| 203 | } |
| 204 | } |