blitz-foundation / monkey2

zlib License
3 stars 0 forks source link

Can't replace material on copied entity #97

Open Pharmhaus-2 opened 5 years ago

Pharmhaus-2 commented 5 years ago

Original Author: DruggedBunny

One for if/when you return!

Is there a way to replace the default material on a copied entity? The copied entity's material seems to remain pointed at the original.

Imagine intentional, since it's a copy, but it means I can't currently create my generic SmokeParticle model and then set colours independently on its copies...

Also, I tried assigning Material (ie. default material) and Materials[0], and only the latter works. Should Material be read-only? Not sure what effect assigning it is having, if any...

Press M below to change the copy's material! Original model's material changes...

Namespace myapp3d

#Import "<std>"
#Import "<mojo>"
#Import "<mojo3d>"

Using std..
Using mojo..
Using mojo3d..

Class MyWindow Extends Window

    Field _scene:Scene
    Field _camera:Camera
    Field _light:Light
    Field _donut:Model

    Field test:Model

    Method New( title:String="Simple mojo3d app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )

        Super.New( title,width,height,flags )
    End

    Method OnCreateWindow() Override

        'create (current) scene
        _scene=New Scene
        _scene.ClearColor = New Color( 0.2, 0.6, 1.0 )
        _scene.AmbientLight = _scene.ClearColor * 0.25
        _scene.FogColor = _scene.ClearColor
        _scene.FogNear = 1.0
        _scene.FogFar = 200.0

        'create camera
        _camera=New Camera( Self )
        _camera.AddComponent<FlyBehaviour>()
        _camera.Move( 0,2.5,-5 )

        'create light
        _light=New Light
        _light.CastsShadow=True
        _light.Rotate( 45, 45, 0 )

        'create donut
        Local donutMaterial:=New PbrMaterial( Color.Red, 0.05, 0.2 )
        _donut=Model.CreateTorus( 2,.5,48,24,donutMaterial )
        _donut.Move( 0,2.5,0 )

        test = _donut.Copy ()
        test.Move (5, 0, 0)

    End

    Method OnRender( canvas:Canvas ) Override

        If Keyboard.KeyHit (Key.M) test.Materials[0] = New PbrMaterial (Color.Blue)
'       If Keyboard.KeyHit (Key.M) test.Material = New PbrMaterial (Color.Blue)     ' No effect

        RequestRender()
        _donut.Rotate( .2,.4,.6 )
        _scene.Update()
        _camera.Render( canvas )
        canvas.DrawText( "FPS="+App.FPS,0,0 )
    End

End

Function Main()

    New AppInstance

    New MyWindow

    App.Run()
End