SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

Import result is wrong with this COLLADA model #414

Open SamuelTallet opened 4 years ago

SamuelTallet commented 4 years ago

SketchUp Version: 2017 OS Platform: Windows 10

Hello,

I'm trying to import a COLLADA model. There's no error triggered but result is incorrect. See below.

Expected result is:

pcon_planner_result

But I get this instead:

sketchup_result

Sketchup.active_model.import('C:/Temp/Debug/azalea_model/Azalea.dae')

Here's COLLADA model:

azalea_model.zip

Thanks.

DanRathbun commented 4 years ago

v2017 will not have anymore releases. Have you tried this on any later versions ?

Have you read any of the Application Release Notes (current | older) or API Release Notes to see if there has been any work on the DAE importer since your version was released ?

(BTW, There is no difference between the method you show and the manual command from the menu. The meaning is that this is not a specific API issue, it's core application issue.)

SamuelTallet commented 4 years ago

v2017 will not have anymore releases. Have you tried this on any later versions ?

No. If you or someone else having SketchUp 2019.3 could test if problem is still present... It'd be great.

Have you read any of the Application Release Notes (current | older) or API Release Notes to see if there has been any work on the DAE importer since your version was released ?

Yes. I have read release notes: my bug is not mentioned.

(BTW, There is no difference between the method you show and the manual command from the menu. The meaning is that this is not a specific API issue, it's core application issue.)

Should I post my issue at another place? If yes: where?

MSP-Greg commented 4 years ago

Have you tried this on any later versions ?

I saw the same issue with SU 2018 & 2019. Don't have any other apps that can open a dae file...

SamuelTallet commented 4 years ago

Have you tried this on any later versions ?

I saw the same issue with SU 2018 & 2019. Don't have any other apps that can open a dae file...

Thanks for testing. To open DAE and many other formats: I use pCon.planner software. (It's free.)

DanRathbun commented 4 years ago

Should I post my issue at another place? If yes: where?

For now, No. I'm looking at the file in Notepad++. It says it was generated by the Assimp Exporter.

Examining in SU2018, I see that this is a transparent texture component (which is nice as it keeps filesize and geometry down.) The foliage faces have some issues. Their edges need to be softened/smoothed (and/or hidden,) and the backs of the faces need to be painted with a 100% transparent material of any color.

What is happening is that the Assimp Exporter (IMO) is making incorrect assumptions (or export settings were incorrect.) I cannot say which as I've never used Assimp libraries.

Besides having the foliage face's edges showing, Assimp assumed incorrectly, and exported a transparent "Default Material". This is the main problem you see. In SketchUp a "Default Material" is not really a material (and so cannot have a texture.) In reality the "Default Material" is when a face (or back face) has it's material property set to nil (which means it is unset.) This means that the face will be rendered by the engine with either the parent instance's material setting (which this component does not have,) or the current SketchUp style's front (or back) colors.

These default colors are not materials and so cannot have textures nor transparency.


To fix ...

After importing (and placing 1 instance at the origin) ... activate the Select tool (spacebar) ...

Double-click the instance to edit the definition's entities, and window select everything.

Right-click the selection, and choose Make Group from the context menu.

Choose (from the "In Model" Materials collection in the Materials inspector panel,) the transparent solid grey material imported that whose name is "<auto>". Then click the Edit tab of the inspector, and grab the Opacity slider and move it to the left til it is set to 0. Click the Select tab again, you'll see the icon has changed. Move the cursor into the modeling area, and you'll see the Paint Bucket tool is active and ready to paint. Click on geometry of the group instance you just made from outside it. (It should still be selected.) This assigns the default material to the entire group instance which causes the SketchUp render engine to use this parent material to render all the unassigned child backfaces.

EDIT: A sidenote to explain why we are adding a nesting level with the group. We do this to protect the instances when you actually use them in a model. In case a bush instance gets accidentally painted with the bucket tool, and because You cannot program the definition to assign default materials to instances at insertion time. (Although I've filed a request here to do so.)

Then ... activate the Select tool (spacebar) ... and double-click the group instance to edit the group definition's entities, and window select everything.

Filter the edges and set them hidden, soft and smooth, by pasting this code snippet into the Ruby console (with the selection still active) ...

Sketchup.active_model.start_operation('Treat Edges',true);
Sketchup.active_model.selection.grep(Sketchup::Edge) {|e| e.hidden= e.soft= e.smooth= true };
Sketchup.active_model.commit_operation

... press enter. (When it's done, true will be returned.)

Click on empty space to exit the group and again to exit the component.

I'd suggest renaming the component's materials at this point. Go back to the Material inspector panel, and in turn, select each of the 4 materials and rename them "<auto>" to "transparent", "<auto>1" to "stem", "<auto>2" to "foliage 1", "<auto>3" to "foliage 2".

Then ... activate the Select tool again (because the Paint Bucket got activating whilst in the inspector.)

Switch to the Components inspector panel, click the house button for the "In Model" components collection, and change the display name for the definition to "Azalea". Add a nifty description if you care. Then right click the definition item in the Select list and choose "Save As...", and save it out to your local collection of nifty bush components.

Lastly ... activate the Select tool again (because the PlaceComponent tool was activated.)


Back to your initial question. It may be that if this is an Assimp Exporter issue, then an issue needs to be logged where Assimp issues are logged. Most likely it's repository ...

https://github.com/assimp/assimp

If you do file an issue, you reference either this issue (it's in the browser address bar,) or my specific comment. Get my comment's URL from the time link following the word "commented" at the top of my post. (It won't matter if Thomas closes this issue, which will likely happen as it's not a SketchUp API issue. It still can be accessed and read as a closed issue. Ie, "open" and "closed" is just a filter property.)

SamuelTallet commented 4 years ago

Thanks a lot for your investigation. Model is well rendered outside SketchUp. So it's a SketchUp issue?

DanRathbun commented 4 years ago

Model is well rendered outside SketchUp.

Testing in 1 viewer IMO is not a definitive test.

Also, different applications do rendering differently. Do not assume that because DAE/Collada organizes it's data and expects rendering to be done in a certain way with raw collada, does not mean applications will mimic this (even if they use OpenGL.) Keep in mind that DAE/Collada is a data transport format meant to share geometric data between applications. It not really meant as a library or end user file format. (Refer to the specs at Khronos.org for a more in depth explanation.)

So it's a SketchUp issue?

Not necessarily. When imported, SketchUp treats it as a component definition import and a component instance placement (in one operation.)

But the model does not seem to have been organized to serve well as a SketchUp component. I described (I thought quite well,) what the imported definition entities had as issues.

It comes into SketchUp as a component with no nesting of any geometry at all. As I explained above, it needs to be nested inside a group so that the transparent default material can be assigned to this parent so that the geometry foliage backfaces can be rendered using the parent's transparent material.

I fixed the imported geometry as explained above, and exported from SketchUp to DAE/Collada as "Azalea_SU_Export.dae". And you'll now notice the nesting of the geometric group node (and subordinate instance_geometry elements ...

    <library_nodes>
        <node id="ID4" name="Azalea">
            <node id="ID5" name="group_0">
                <matrix>1 0 0 -105.1866 0 1 0 -103.1378 0 0 1 -20.9078 0 0 0 1</matrix>
                <instance_geometry url="#ID6">

Azalea_SU_Export.zip

There is also an issue with hidden edges for meshes. When exported and imported back into SketchUp the border edges of the leaf meshes were visible again and I had to go through the hide edit again.

So is it a SketchUp issue? My conclusion is no. DAE/Collada is a foreign format to SketchUp. There's always cleanup that needs to be done when importing external formats. In addition your "azalea.zip" model (whatever it was drawn in) could have been better setup for SketchUp import before it was exported to DAE.

prachtan commented 4 years ago

IMHO is more a Feature request than issue.

The SU Collada importer could have an additional options: "Double sided" and "Hide edges"

(@thomthom, maybe it could be added to the next SU version, the double sided option is internally supported by the importer, triggered by technique, for sure, the following workaround should be described somewhere, for example under Importing a COLLADA file )

For your case, there is a manual workaround, you'll need to add an extra technique:

        <extra>
          <technique profile="GOOGLEEARTH">
              <double_sided>1</double_sided>
          </technique>
        </extra>

under effect:

  <library_effects>
    <effect id="xxx" name="yyy">
      <profile_COMMON>
        <technique sid="standard">
          ...
        </technique>

        <!-- Add extra technique here -->
        <extra>
          <technique profile="GOOGLEEARTH">
              <double_sided>1</double_sided>
          </technique>
        </extra>

        </profile_COMMON>
    </effect>  

or find out how to force your software to add this entry.

Azalea_double_sided.zip

SamuelTallet commented 4 years ago

@prachtan Good catch! Thanks for workaround.

DanRathbun commented 4 years ago

But that seems to only solve the backface not getting transparent material issue. The edges are still not hidden.

thomthom commented 4 years ago

Am I correct in interpreting this as a request for SketchUp's DAE importer to expand it's feature capability to read this <extra>...<double_sided> tag to apply a texture to both sides of a face?

DanRathbun commented 4 years ago

I did say so above (in the 2nd post) that this is a Core importer issue.

And as also mentioned above by @prachtan the DAE import options could have also have a "Hide Edges" option in addition to "Double Sided transparent materials".

thomthom commented 4 years ago

Just confirming, there was a lot of information here. I'll forward this to the core and close this issue since it's technically an API issue.

DanRathbun commented 4 years ago

... Core issue. 🤣

prachtan commented 4 years ago

Nope, this is more a request for adding two extra checkboxes under UI of Collada Importer options, to controll if surfaces will be (forcedto be ) "double sided" and to "hide edges".

At this moment, the DAE importer can be forced to make surface double sided only by manually adding (as long as this can't be generated by source) an extra technique "GOOGLEEARTH".