Skip to content

Implement Graphics.drawGraphicsData and readGraphicsData - #13

Open
roncarbot wants to merge 5 commits into
devfrom
feature/graphics-data-api
Open

Implement Graphics.drawGraphicsData and readGraphicsData#13
roncarbot wants to merge 5 commits into
devfrom
feature/graphics-data-api

Conversation

@roncarbot

Copy link
Copy Markdown

Summary

  • Implements Graphics.drawGraphicsData() by walking IGraphicsData items (data_type) and dispatching to the existing beginFill / beginGradientFill / beginBitmapFill / endFill / lineStyle / lineGradientStyle / lineBitmapStyle / drawPath machinery.
  • Implements Graphics.readGraphicsData() for this Graphics object (no display-list recurse). Recorded fill/stroke paths survive tessellation/endFill so a solid fill + path can round-trip. Output uses SolidFillStyle / GradientFillStyle / BitmapFillStyle, GraphicsEndFill, GraphicsStrokeStyle, and GraphicsPath with MOVE_TO / LINE_TO / CURVE_TO only.
  • Adds GraphicsEndFill ([graphicsdata EndFill]). Existing drawing APIs are unchanged.

Test plan

  • beginFill + drawPath/drawRect then readGraphicsData() returns a solid fill, path, and end fill
  • drawGraphicsData() of that result redraws the same shape
  • lineStyle + path round-trips a GraphicsStrokeStyle + path
  • clear() drops recorded data
  • Existing beginFill / lineTo / endFill drawing still works

Walk IGraphicsData by data_type into the existing fill/stroke/path APIs, keep recorded paths after tessellation, and serialize MOVE_TO/LINE_TO/CURVE_TO plus fills, strokes, and GraphicsEndFill.
applyPattern replaces graphicsData[0]; if that slot was a stroke or empty,
the clothing interiors never got the new GraphicsBitmapFill. Also clone
queued ShapeTags and fall back to sourceGraphics / triangle contours.
Queued and active held the same live path objects as _recorded_*, so merging
them in _collectRecordedPaths was redundant and could duplicate fills. Record
once by identity and skip shape-fallback bitmaps already emitted from paths.
Comment thread lib/managers/MaterialManager.ts Outdated
newmat.alphaBlending = true;
newmat.useColorTransform = true;
newmat.bothSides = true;
return newmat;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@roncarbot you return newmat here but if you have a transform don't you need to return the correct _bitmapMaterialTransform material. what eventualities is the image arg used?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch to double-check. When image is set we intentionally return a per-image material (image.id + transform flag), not the shared _bitmapMaterialTransform. The shared transform material is only the fallback for the no-image path below (default 8×8 placeholder + animateUVs).

image is used for author-time / beginBitmapFill bitmaps so each BitmapData gets its own material (and its own mip/NPOT handling) instead of all fills fighting over one shared material. The transform flag on that path only turns on animateUVs for that per-image material — same UV-animation behaviour as _bitmapMaterialTransform, without sharing the texture slot.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a per-image material is not needed, the material is only holding shader information (which is the same for every bitmap material) and the image is set on the style property of the shape. If you look at where getMaterialForBitmap() is implemented, it is accompanied by a style.image setting when appropriate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right — I was over-fitting. Materials here are shared shader state; the bitmap belongs on style.image (both GraphicsFactoryFills and the ShapeTag path already set that). I've dropped the per-image material pool and the extra image arg; getMaterialForBitmap(transform) is back to the shared _bitmapMaterial / _bitmapMaterialTransform pair. Kept the mipmap=false sampler change, which was the part that actually fixed the black NPOT fills.

Comment thread lib/Graphics.ts
&& !this._shapes.length
&& !this._recorded_fill_pathes.length
&& this.sourceGraphics)
source = this.sourceGraphics;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think sourceGraphics is being used for anything, can you check and if not, remove from source?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It is still used — three places in this file:

  1. start / end getters fall through to sourceGraphics when this instance hasn’t set its own.
  2. copyTo sets graphics.sourceGraphics = this so clones keep a link back to the symbol Graphics.
  3. readGraphicsData (this block) — if the instance has no queued ShapeTags, no shapes, and no recorded fill paths, it reads from sourceGraphics so timeline instances that share / clone a symbol still reconstruct fills.

Happy to rename or tighten the fallback if you’d rather readGraphicsData only ever look at this, but I wouldn’t remove the field while those three paths still need it.

Bitmap lives on style.image; MaterialManager only needs one transform and
one non-transform bitmap material. NPOT mipmap=false sampler fix stays.
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