Re: [4.60 beta] Ribbon Effect
Publié : mar. 12/avr./2011 14:23
Magnifique !
Bon, je comprends un peu mieux comment ça marche, merci beaucoup!
Et quand même, parce que quelquefois c'est pratique de créer un material en dans le code (et aussi parce que je suis un peu pénible
), j'ai modifié mon code pour que les ribbons soient transparents sans utiliser de ".material":
Bon, je comprends un peu mieux comment ça marche, merci beaucoup!
Et quand même, parce que quelquefois c'est pratique de créer un material en dans le code (et aussi parce que je suis un peu pénible

Code : Tout sélectionner
; Window size
#SCREENWIDTH = 800
#SCREENHEIGHT = 500
Structure ball_struct
numEntity.i
numNode.i
numRibbon.i
timer.f
EndStructure
Global NewList ball.ball_struct()
;- initialization
InitSprite()
InitEngine3D()
InitKeyboard()
;- Window
OpenWindow(0, 0, 0, #SCREENWIDTH, #SCREENHEIGHT, "Ribbon FX test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, #SCREENWIDTH,#SCREENHEIGHT, 0, 0, 0,#PB_Screen_SmartSynchronization)
;-Texture
Add3DArchive(".",#PB_3DArchive_FileSystem)
CreateImage(0,128, 128)
StartDrawing(ImageOutput(0))
Box(0, 0, 128, 128, $FFFFFF)
StopDrawing()
SaveImage(0,"temp.bmp")
FreeImage(0)
LoadTexture(0,"temp.bmp")
DeleteFile("temp.bmp")
; Ribbon texture
CreateImage(0,128, 1)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($000000)
GradientColor(0.5, $FFFFFF)
FrontColor($0000)
LinearGradient(0, 0, 128, 0)
Box(0, 0, 128, 1)
StopDrawing()
SaveImage(0,"temp2.bmp")
FreeImage(0)
LoadTexture(1,"temp2.bmp")
DeleteFile("temp2.bmp")
; Colors
Global Dim color.i(7)
Global Dim ribbonColor.i(7)
color(0) = $FF0000:ribbonColor(0) = $770000
color(1) = $00FF00:ribbonColor(1) = $007700
color(2) = $0000FF:ribbonColor(2) = $000077
color(3) = $FFFF00:ribbonColor(3) = $777700
color(4) = $FF00FF:ribbonColor(4) = $770077
color(5) = $00FFFF:ribbonColor(5) = $007777
color(6) = $0077FF:ribbonColor(6) = $003377
;-Materials
CreateMaterial(999,TextureID(0)) ; walls
CreateMaterial(998,TextureID(1)) ; ribbons
MaterialDepthWrite(998, #False)
DisableMaterialLighting(998,#True)
MaterialBlendingMode(998,#PB_Material_Add)
MaterialFilteringMode(998,#PB_Material_None)
For i=0 To 6
CreateMaterial(i,TextureID(0)) ; balls
MaterialAmbientColor(i,color(i))
Next i
;- Entities
; walls
planeMesh = CreatePlane(#PB_Any,2,2,10,10,1,1)
ground = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
EntityPhysicBody(ground, #PB_Entity_StaticBody,1,1,0)
ceiling = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(ceiling,180,0,0)
EntityLocate(ceiling,0,20,0)
EntityPhysicBody(ceiling, #PB_Entity_StaticBody)
backWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(backwall,90,0,0)
EntityLocate(backwall,0,10,-10)
EntityPhysicBody(backwall, #PB_Entity_StaticBody,1,1,0)
frontWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(frontWall,270,0,0)
EntityLocate(frontWall,0,10,10)
EntityPhysicBody(frontWall, #PB_Entity_StaticBody,1,1,0)
HideEntity(frontWall,#True)
leftWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(leftWall,0,0,270)
EntityLocate(leftWall,-10,10,0)
EntityPhysicBody(leftWall, #PB_Entity_StaticBody,1,1,0)
rightWall = CreateEntity(#PB_Any, MeshID(planeMesh), MaterialID(999))
RotateEntity(rightWall,0,0,90)
EntityLocate(rightWall,10,10,0)
EntityPhysicBody(rightWall, #PB_Entity_StaticBody,1,1,0)
; balls
sphereMesh = CreateSphere(#PB_Any, 0.5)
For i=1 To 20
ballcolor = Random(6)
AddElement(ball())
ball()\numEntity = CreateEntity(#PB_Any, MeshID(sphereMesh), MaterialID(ballcolor))
EntityLocate(ball()\numEntity, 8 - Random(16),10 + 8 - Random(16),8 - Random(16))
EntityPhysicBody(ball()\numEntity, #PB_Entity_SphereBody, 1,0.7,0)
ApplyEntityImpulse(ball()\numEntity,20-Random(40),20-Random(40),20-Random(40) )
;- Ribbons
ball()\numNode = CreateNode(#PB_Any)
ball()\numRibbon = CreateRibbonEffect(#PB_Any,MaterialID(998),NodeID(ball()\numNode),1,50,0.8,20)
RibbonEffectColor(ball()\numRibbon,ribbonColor(ballcolor),$FFFFFF)
Next i
;- Camera
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,10,35)
CameraLookAt(0,0,10,0)
;- Light
AmbientColor(RGB(92,92,92))
CreateLight(0,RGB(160,160,255),-200,300,0)
WorldShadows(#PB_Shadow_Additive)
;- Main loop
Repeat
Delay(1)
While WindowEvent() : Wend
If ExamineKeyboard()
;- Return : Display FPS
If KeyboardReleased(#PB_Key_Return)
MessageRequester("Infos","FPS = " + Str(Engine3DFrameRate(#PB_Engine3D_Average)))
EndIf
EndIf
; Move the balls
ForEach ball()
; If the ball is on the ground for too long, give it a little impulse
If EntityY(ball()\numEntity) < 0.7
ball()\timer + 1
Else
ball()\timer = 0
EndIf
If ball()\timer > 50
ApplyEntityImpulse(ball()\numEntity,20-Random(40),15+Random(15),20-Random(40) )
EndIf
; The ribbon is attached to the node, so the node must follow the ball
NodeLocate(ball()\numNode,EntityX(ball()\numEntity),EntityY(ball()\numEntity),EntityZ(ball()\numEntity))
Next ball()
; Render
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End