我需要紋理到一個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.! !