I am trying to export a DAE centered at the point around a selection with a Python script. When I do this manually with the export Wizard, I select "Center" to calculate the global offset. The exported file then contains information with small numbers for the float_arrays, as it appears to have been centered correctly:
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>float_array</SPAN> <SPAN class="attr-name token">id</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>GeometrySource2-array<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">count</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>150<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN>-1.274902462959289 0 5.1300048828125 -0.6110070943832397 0 4.382179498672486 -0.6110070943832397 2 4.382179498672486...[etc]<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>float_array</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
When I imitate this with the following export options through python, it does not appear that the selection is being centered. Can anyone advise me about the correct way to center a selection programmatically?
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">exportDae</SPAN><SPAN class="punctuation token">(</SPAN>toExport<SPAN class="punctuation token">,</SPAN> directory<SPAN class="punctuation token">,</SPAN> name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
settings <SPAN class="operator token">=</SPAN> DAEExportModelSettings<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># set the export path and name of associated files</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setOutputPath<SPAN class="punctuation token">(</SPAN>directory<SPAN class="punctuation token">)</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setBaseName<SPAN class="punctuation token">(</SPAN>name<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># beware, collada 1.5.x doesn't seem to work when exporting these</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setCOLLADAVersion<SPAN class="punctuation token">(</SPAN>colladaVersion<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># create a node with shape's name</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setCreateShapeGroups<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># "Reuse asset instances, merge generated meshes by material"</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setMeshGranularity<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"INSTANCED"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># group by material type instead of with 5 billion little pieces</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setMeshGranularity<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PER_MATERIAL"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># THESE ARE THE LINES WHERE I ATTEMPT TO CENTER THE SELECTION</SPAN>
<SPAN class="comment token"># "zero" the object(s) to remove geographic coordinates</SPAN>
position <SPAN class="operator token">=</SPAN> ce<SPAN class="punctuation token">.</SPAN>getPosition<SPAN class="punctuation token">(</SPAN>toExport<SPAN class="punctuation token">)</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setGlobalOffset<SPAN class="punctuation token">(</SPAN>position<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># export associated terrain</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setTerrainLayers<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"TERRAIN_ALL_SELECTED"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># export to a single file (instead of one per material)</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setFileGranularity<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MEMORY_BUDGET"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># export the models but default to start shape if problem</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setExportGeometry<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MODEL_GEOMETRY_FALLBACK"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># overwrite any existing files at that location!!!</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setExistingFiles<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"OVERWRITE"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># delineater for shape name clashes</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setShapeNameDelimiter<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"_"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># output log</SPAN>
settings<SPAN class="punctuation token">.</SPAN>setWriteLog<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
ce<SPAN class="punctuation token">.</SPAN>export<SPAN class="punctuation token">(</SPAN>toExport<SPAN class="punctuation token">,</SPAN> settings<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This will contain float arrays with MUCH larger values, corresponding to the location of the shapefile, which indicates to me that "zeroing" my selection for the export was unsuccessful:
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>float_array</SPAN> <SPAN class="attr-name token">id</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>GeometrySource0-array<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">count</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>72<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN>543176.7597654069 0 -3.281641101196114e6 543177.5401077866 0 -3.281641726548671e6 ...[etc]<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>float_array</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
How can I implement the functionality of the "Center" button on the collada export dialogue in python?
Thanks!