如何将图像插入到 PolygonMorph 中?

发布于 2024-08-17 08:59:00 字数 235 浏览 6 评论 0原文

我需要将纹理放入 PolygonMorph,但这些似乎需要 InfiniteForm 作为颜色/填充。

InfiniteForm 不是解决方案,因为我需要稍后旋转 PolygonMorph 并且移动 PolygonMorph 也会对显示的纹理产生副作用。
如果也可以缩放插入的纹理,那将非常有用。

在不替换现有 PolygonMorph(或至少保持 PolygonMorph 的形状)的情况下,您将如何做到这一点?

I need to get a texture into a PolygonMorph, but these seem to require an InfiniteForm as color/ filling.

The InfiniteForm is no solution as i need to rotate the PolygonMorph later on and moving the PolygonMorph around also has sideeffects on the displayed texture.
It would be very useful if it would be possible to scale the inserted texture as well.

How would you do this without replacing the existing PolygonMorph (or at least keeping the PolygonMorph's shape)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2024-08-24 08:59:00

这是解决您问题的另一个想法。
该解决方案包括 2 个阶段。

第 1 阶段:(drawTextures)我们使用 BitBlt 用我们的纹理图块填充表单。该形式存储在称为纹理的实例变量中。此表单在第 2 阶段中进行剪辑

第 2 阶段:(clipTextures) 现在我们生成一个形状像我们的多边形且具有多边形filledForm 的表单。然后我们从完全黑色的形式中减去它。现在我们有了一个负的多边形形状。这样我们就可以剪辑纹理了。现在我们可以创建一个图像变形并将其添加到多边形或任何我们想要用它做的事情中。

不幸的是,filledForm 实现无法处理凸形状。所以要小心你的多边形的样子。

该解决方案非常快,也可以在运行时应用。我们每 10 毫秒改变一次多边形的形状,并且渲染效果很好。

!PgiTexturedMorph methodsFor: 'graphics' stamp: 'pre 2/12/2011 13:30:15.156'!
    drawTexture
        | textureForm aTexture aBitBlt |

        textureForm := Form extent: (self shape extent) depth: 32.
        aTexture := self baseImage deepCopy .
        textureForm := Form extent: (self shape extent) depth: 32.
        (0 to: ((textureForm extent x) / (aTexture extent x))) do: [ :eachX | 
            (0 to: ((textureForm extent y) / (aTexture extent y))) do: [ :eachY |
                aBitBlt := BitBlt   destForm: textureForm 
                                sourceForm: aTexture 
                                fillColor: nil
                                combinationRule: 7 
                                destOrigin: (eachX * (aTexture extent x))@(eachY *(aTexture extent y)) 
                                sourceOrigin: 0@0 
                                extent: (aTexture extent) 
                                clipRect: (textureForm computeBoundingBox).
                aBitBlt copyBits.
            ]].

        self texturing: textureForm.! !

    !PgiTexturedMorph methodsFor: 'graphics' stamp: 'pre!
    clipTextures
        | clippingForm aBitBlt |

        clippingForm := (Form extent: (self shape extent + (1@0))) fillBlack.
        aBitBlt := BitBlt   destForm: clippingForm 
                        sourceForm: (self shape filledForm) 
                        fillColor: nil
                        combinationRule: 6 
                        destOrigin: 0@0
                        sourceOrigin: 0@0 
                        extent: (self shape extent) 
                        clipRect: (clippingForm computeBoundingBox).
        aBitBlt copyBits.
        aBitBlt := BitBlt   destForm: (self texturing) 
                        sourceForm: (clippingForm ) 
                        fillColor: nil
                        combinationRule: 17 
                        destOrigin: 0@0
                        sourceOrigin: 0@0 
                        extent: (clippingForm  extent) 
                        clipRect: (self texturing computeBoundingBox).
        aBitBlt copyBits.

        self texturePart image: (self texturing).
        self texturePart changed.! !

Heres another idea for your problem.
The solution includes 2 phases.

Phase 1: (drawTextures) We use BitBlt to fill a Form with our texture tiles. The form is stored in an instance variable called texturing. This form is clipped in phase 2

Phase 2: (clipTextures) Now we produce a form which is shaped like our polygon with polygon filledForm. Afterwards we substract this from a completley black form. Now we have a negative shape of the polygon. With this we clip the texturing. Now we can create an Image Morph and add it to the polygon or whatever we want to do with it.

Unfortunately the filledForm implementation cannot deal with convec shapes. So be careful how your polygon looks like.

This solution is pretty fast and can also be applied during run time. We are changing the shape of the polygon every 10msec and its rendering fine.

!PgiTexturedMorph methodsFor: 'graphics' stamp: 'pre 2/12/2011 13:30:15.156'!
    drawTexture
        | textureForm aTexture aBitBlt |

        textureForm := Form extent: (self shape extent) depth: 32.
        aTexture := self baseImage deepCopy .
        textureForm := Form extent: (self shape extent) depth: 32.
        (0 to: ((textureForm extent x) / (aTexture extent x))) do: [ :eachX | 
            (0 to: ((textureForm extent y) / (aTexture extent y))) do: [ :eachY |
                aBitBlt := BitBlt   destForm: textureForm 
                                sourceForm: aTexture 
                                fillColor: nil
                                combinationRule: 7 
                                destOrigin: (eachX * (aTexture extent x))@(eachY *(aTexture extent y)) 
                                sourceOrigin: 0@0 
                                extent: (aTexture extent) 
                                clipRect: (textureForm computeBoundingBox).
                aBitBlt copyBits.
            ]].

        self texturing: textureForm.! !

    !PgiTexturedMorph methodsFor: 'graphics' stamp: 'pre!
    clipTextures
        | clippingForm aBitBlt |

        clippingForm := (Form extent: (self shape extent + (1@0))) fillBlack.
        aBitBlt := BitBlt   destForm: clippingForm 
                        sourceForm: (self shape filledForm) 
                        fillColor: nil
                        combinationRule: 6 
                        destOrigin: 0@0
                        sourceOrigin: 0@0 
                        extent: (self shape extent) 
                        clipRect: (clippingForm computeBoundingBox).
        aBitBlt copyBits.
        aBitBlt := BitBlt   destForm: (self texturing) 
                        sourceForm: (clippingForm ) 
                        fillColor: nil
                        combinationRule: 17 
                        destOrigin: 0@0
                        sourceOrigin: 0@0 
                        extent: (clippingForm  extent) 
                        clipRect: (self texturing computeBoundingBox).
        aBitBlt copyBits.

        self texturePart image: (self texturing).
        self texturePart changed.! !
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文