我需要纹理到一个PolygonMorph,但这些似乎需要一个InfiniteForm作为颜色/填充。如何将图像插入PolygonMorph?
InfiniteForm没有解决方案,因为我需要稍后旋转PolygonMorph,并且移动PolygonMorph也会在显示的纹理上产生副作用。
如果可以缩放插入的纹理,这将是非常有用的。
如果不替换现有的PolygonMorph(或至少保持PolygonMorph的形状),你会怎么做?
我需要纹理到一个PolygonMorph,但这些似乎需要一个InfiniteForm作为颜色/填充。如何将图像插入PolygonMorph?
InfiniteForm没有解决方案,因为我需要稍后旋转PolygonMorph,并且移动PolygonMorph也会在显示的纹理上产生副作用。
如果可以缩放插入的纹理,这将是非常有用的。
如果不替换现有的PolygonMorph(或至少保持PolygonMorph的形状),你会怎么做?
继承人您的问题的另一个想法。 该解决方案包括2个阶段。
阶段1:(绘制贴图)我们使用BitBlt来填充表单和我们的纹理贴图。表单存储在一个名为texturing的实例变量中。这种形式被剪辑在阶段2
阶段2:(clipTextures)现在我们生成一个形状像我们的多边形与多边形filledForm。之后,我们从完整的黑色表格中减去这个。现在我们有一个多边形的负形状。有了这个,我们剪下了纹理。现在我们可以创建一个图像变形并将其添加到多边形或任何我们想要使用它。
不幸的是,filledForm实现不能处理convec形状。所以要小心你的多边形是怎样的。
这个解决方案非常快,也可以在运行时应用。我们正在改变每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: [email protected]
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 + ([email protected]))) fillBlack.
aBitBlt := BitBlt destForm: clippingForm
sourceForm: (self shape filledForm)
fillColor: nil
combinationRule: 6
destOrigin: [email protected]
sourceOrigin: [email protected]
extent: (self shape extent)
clipRect: (clippingForm computeBoundingBox).
aBitBlt copyBits.
aBitBlt := BitBlt destForm: (self texturing)
sourceForm: (clippingForm)
fillColor: nil
combinationRule: 17
destOrigin: [email protected]
sourceOrigin: [email protected]
extent: (clippingForm extent)
clipRect: (self texturing computeBoundingBox).
aBitBlt copyBits.
self texturePart image: (self texturing).
self texturePart changed.! !