Skip to content

Conversation

@tristan-huber
Copy link
Contributor

Fixes an issue where deserialized drawings failed to sketchOnPlane.

Root problem was that the output streams used in serialization had default precision (ie, 6 sig figs) and this would badly skew the serialized curves. Particularly a problem with text where the skew of each line segment would cause letters to no longer be a closed form.

Minimal repro in replicad studio with this script:

const { draw, drawText, Plane } = replicad;

const main = () => {
  const p = new Plane().pivot(0, "Y");
  const text = drawText("N");

  const serial = text.serialize();
  const newText = replicad.deserializeDrawing(serial);
  return newText.sketchOnPlane(p).extrude(5);
}

This fix sets the precision in the ostringstream to 17 digits which should be high enough for doubles (ie the Standard_Real used by Opencascade). I've made the same change for Shape3d serialization as well.

floating point numbers are not truncated.

This was particularly an issue for Drawings
- -sALLOW_MEMORY_GROWTH=1
- -sEXPORTED_RUNTIME_METHODS=["FS"]
- -O3
- -sDISABLE_EXCEPTION_CATCHING=1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you added this?

Copy link
Contributor Author

@tristan-huber tristan-huber Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! I wasn't intending to add this. Actually you beat me to it, but I had a question about this line. As I understand it everything in build-config directory is auto-generated during the pnpm buildWasm task. And it's during that task where I see this line get added. It's causing downstream changes that aren't desirable, eg: the replicad_with_exceptions.wasm file is 8mb smaller which seems super suspicious.

If I run pnpm buildWasm in packages/replicad-opencascade on the main branch I also see this line added to build-config/custom_build_with_exceptions.yml. So I think the issue is somewhere in my build process as opposed to being due to the diff on defaults.yml.

Has anything changed lately on the build process that I maybe haven't picked up? Given where DISABLE_EXCEPTION_CATCHING is set in the build-source directory it doesn't make sense to me that this would be added here, so I suspect something's wrong in my understanding of the build-config generation process.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - there is something you are missing.

You don't need to change manually every single file - there is a build step. You can run pnpm generateConfig (you need to have ytt installed) and it will generate the different build files with the correct options.

@sgenoud sgenoud force-pushed the serialize-with-precision branch from 6b24054 to 29d603a Compare September 19, 2025 13:47
@sgenoud sgenoud force-pushed the serialize-with-precision branch from 29d603a to 6f246ef Compare September 19, 2025 14:16
@sgenoud sgenoud merged commit bea0248 into sgenoud:main Sep 19, 2025
1 check failed
@tristan-huber
Copy link
Contributor Author

Sweet! Thanks for patching this and merging it in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants