RWMesh - Fix lossy encoding of non-ASCII node names in glTF export#1321
RWMesh - Fix lossy encoding of non-ASCII node names in glTF export#1321Clonephaze wants to merge 2 commits into
Conversation
|
Dear @Clonephaze Thank you for your patch. To proceed with integration, please complete signing CLA process: In case if you already have signed CLA, please share ID that OCCT team shared with your by email after accepting of CLA. |
|
After further testing while attempting to use the fix in real world situations, I've found that my current submitted approach is insufficient. The original change to The real problem is in I've attempted to fix this by validating the string with I cannot push to this branch while the PR is blocked, but the corrected diff touches Additionally, I've attempted to write a few unit tests to cover the new behavior. They are in
Happy to rebase and update the PR once the CLA is confirmed. Still waiting for that validation. |
|
@gkv311 Thank you for the feedback Yeah that makes sense, I don't know why I assumed a fallback to only one encoding would be appropriate. Especially for global userbase. A fundamental misunderstanding I had was that this encoding issue was specific to legacy STEP files and that modern STEP files (like those exported from Fusion 360) handle writing UTF-8 correctly from the start. The escape-based path in cleanText handles modern files correctly. Would the right direction be to keep IsStrictUtf8() as a detection step but replace the fallback with just a warning, telling the user to set read.step.codepage to match their file's encoding? That seems to align with what you described. If so I'll start working on that change and updating the tests to look for the warning instead of the fallback behavior. |
I would find it useful, but cannot say for implications and other end users. I don't know which criteria could be used to validate UTF-8 or UTF-16 - Probably you may start with smaller steps and propose adding a method to Then one may suggest some tool for checking string issues in existing XCAF document (that might be not that simple to traverse all occurrences of string in the document, but probably starting from very basics like names of assembly elements might useful enough) or to imply these check in string conversion routines (but as this used only within STEP import, you wouldn't be able to check already translated XCAF documents or imports from other formats like glTF). |

RWMesh::ReadNameAttributeandRWMesh::FormatNameconvert node names fromTCollection_ExtendedString(UTF-16) toTCollection_AsciiString. Lossy for non-ASCII characters, which are replaced with a substitution byte rather than being encoded correctly.The PR just adds the small static helper
ExtendedToUtf8that converts viaNCollection_UtfString<char>, and all call sites inReadNameAttributeandFormatNameare updated to use this helper.Verified with a STEP file containing French part names (
Pièce,Première,butée) which previously produced\ufffdreplacement characters in the glTF JSON chunk. Node names now survive conversion.