Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to apply a glowing texture?

edited April 13 in Codea Craft Posts: 972

I know it’s not even very challenging (in theory) to apply a glowing texture to a model in craft, but I don’t think there’s a default glowing texture**, and I don’t know how to make one...

...does anybody have a glowing material handy?

I think I can actually work out how to apply it once I have it.

** @Simeon maybe worth including in the builtin?

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,587

    @UberGoober if you take a look at the "AR Face" demo project you'll see that you can use the bloom effect, along with emissive materials, to make things glow in Craft

    This is the scene setup:

        -- Setup lighting
        self.scene.ambientColor = color(63, 63, 63, 255)
        self.sunLight = self.scene.sun:get(craft.light)
        self.sunLight.intensity = 0.7
        self.scene.sun.rotation = quat.eulerAngles(80, 0, 0)
    
        -- Setup bloom post processing effect
        self.cameraComponent = self.scene.camera:get(craft.camera)
        self.cameraComponent.hdr = true
        self.cameraComponent.colorTextureEnabled = true
        self.bloom = craft.bloomEffect()
        self.cameraComponent:addPostEffect(self.bloom)
        self.bloom.threshold = 1.5
        self.bloom.intensity = 1.2
        self.bloom.softThreshold = 0.4
        self.bloom.iterations = 8
    

    Then when you switch to the "Glowing Eyes" material it simply uses the basic material but multiplies the diffuse colour by the intensity, which causes it to exceed 1.0 in RGB. This triggers the bloom effect

                name = "Glowing Eyes",
                material = craft.material(asset.builtin.Materials.Basic),
                setup = function(face, material)
                    face.entity.material = face.blankMaterial
                    face.leftEye.material = material
                    face.rightEye.material = material
    
                    -- Combine color and intensity for HDR effects
                    Intensity = 5
                    parameter.color("Color", color(255, 50, 0, 0), function(c)
                        local d = vec3(Color.r/255, Color.g/255, Color.b/255) * Intensity
                        material.diffuse = d
                    end)
    
                    parameter.number("Intensity", 0.0, 100, 5, function(i)
                        local d = vec3(Color.r/255, Color.g/255, Color.b/255) * Intensity
                        material.diffuse = d
                    end)
                end
    
  • edited April 13 Posts: 972

    Thanks @Simeon!

    I got it working in my project and it’s just what I wanted, except maybe I didn’t want the right thing.

    I’ve got a bunch of models the player can select between, and I want to use the glow to indicate the currently selected model.

    So one thing is that can’t see how to turn it off. I tried the obvious entity.material = nil, and I tried entity:remove(craft.material), but those both caused errors.

    How should I switch the glow between models?

  • Posts: 977

    post the code please? i'd like to learn from it. thanks!

  • Posts: 972

    @RonJeffries i’m unclear what code you want to see.

    There’s the code posted by @Simeon up there, which is, you know, up there, and then there’s my code, which is basically the same code just not as good.

    And then there is my attempt to remove the glow effect, which just plain doesn’t work; I am happy to post any of these if you want, I’m just not sure there’s much to learn from it…

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober I think what code @RonJeffries wants is a small working example showing the bloom effect and not have to try to figure out how to code everything.

  • Posts: 977

    right. i had the impression you had something small. no big deal, i'm just curious.

  • Posts: 972

    @dave1707 @RonJeffries oh, gotcha. Thanks for clearing that up dave. In reality this is part of a big other thing but I think I can work up the ol’ spinning blocks to suit this purpose. Hold on a sec...

  • Posts: 972

    Okay this is a good demonstration, in all its buggy glory.

    The toggle is supposed to switch the glow between the two blocks.

  • Posts: 972

    Wait that one was way too buggy. We just want the right bugs, right? Try this one.

  • Posts: 972

    ...or a version using the blocky dude models

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober I stripped your code down to the bare minimum and allowed the bloom to be turned on and off by touching the screen.

    viewer.mode=FULLSCREEN
    
    function setup()    
        scene = craft.scene()
        scene.camera.position=vec3(0,0,-4)
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
        bloom.threshold = 4
        bloom.intensity = 1.2
        bloom.softThreshold = 0.4
        bloom.iterations = 8
    
        createBloom(false)
    end
    
    function createBloom(glow)
        if ground then
            ground:destroy()
        end
        ground = scene:entity()
        ground.model = craft.model.cube(vec3(1,1,1))
        ground.material = craft.material(asset.builtin.Materials.Specular)
        ground.material.map = readImage(asset.builtin.Surfaces.Desert_Cliff_Roughness)
        ground.position = vec3(0,0,0)
        if glow then
            material = craft.material(asset.builtin.Materials.Basic)
            material.diffuse = vec3(2.5,1.5,4)
            ground.material = material
        end
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()
    end
    
    function touched(t)
        if t.state==BEGAN then
            gl=not gl
            createBloom(gl)
        end
    end
    
  • Posts: 977

    cool. is any of that documented somewhere?
    thanks!

  • Posts: 972

    @dave1707 it’s a smart trick but you aren’t actually turning off the glow, right?

    You’re completely destroying the entity each time and rebuilding it from scratch either with or without a glow, I think.

    I think that’s an elegant solution when you strip it all down to the extent that you did, especially because your program has only one entity, but I don’t think it makes sense in the program I’ll be actually be using it in, which needs to keep track of potentially 50+ entities, and needs to be able to turn glows on and off of each of them at will.

    Plus, if there’s no way to turn off a glow without destroying the entity it’s attached to, that’s just, well, weird.

  • SimeonSimeon Admin Mod
    edited April 14 Posts: 5,587

    You can just assign a new material. Or even just adjust the settings of an existing material

    E.g., you can do:

    ground.material.diffuse = <new diffuse color>

    If the diffuse colour is intense enough (> 1.0) and bloom is set, then it will glow.

    viewer.mode=FULLSCREEN
    
    function setup()
        scene = craft.scene()
        scene.camera.position=vec3(0,0,-4)
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
        bloom.threshold = 4
        bloom.intensity = 1.2
        bloom.softThreshold = 0.4
        bloom.iterations = 8
    
        material = craft.material(asset.builtin.Materials.Specular)
        material.map = readImage(asset.builtin.Surfaces.Desert_Cliff_Roughness)
    
        bloomMaterial = craft.material(asset.builtin.Materials.Basic)
        bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
        createGround()
    end
    
    function createGround()
        if ground then
            ground:destroy()
        end
        ground = scene:entity()
        ground.model = craft.model.cube(vec3(1,1,1))
    
        ground.position = vec3(0,0,0)
    
        ground.material = material
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()
    end
    
    function touched(t)
        if t.state==BEGAN then
            gl=not gl
            if gl then
                ground.material = bloomMaterial
            else
                ground.material = material
            end
        end
    end
    
  • edited April 14 Posts: 972

    Okay but @Simeon, in your code you’re still destroying the entity each time. (Edit: @dave1707 corrected me that you’re actually not, sorry about that)

    Attached is a project showing my results when I don’t destroy the entity each time. I can’t get the model’s original skin back.

    Also attached are two screenshots to better describe what I’m after.

    The first image is from my actual project, where I somehow managed to get the glowing effect happening on the original model without obscuring its skin. I can’t understand how I did this because when I paste the same code into this demo project it doesn’t produce the same results. This is the code from my actual project:


    material = craft.material(asset.builtin.Materials.Basic) newEntity.material = material material.blendMode = ADDITIVE -- Combine color and intensity for HDR effects Intensity = 1.5 local effectColor = vec3(200/255, 90/255, 30/255) * Intensity newEntity.material.diffuse = effectColor local effectIntensity = vec3(100/255, 90/255, 130/255) * Intensity newEntity.material.diffuse = effectIntensity

    The second image is the effect I’d like to achieve, from the project I pasted below, except that I need the figure’s skin to be visible in the center, at least a little, instead of just pure white.

    In other words the ideal effect is to have the same skin-visibility as the figure from the first picture (or thereabouts) with the same corona as the second.

  • Posts: 972

    Ok I figured out how my existing project achieved that effect and you’re gonna laugh.

    Maybe. Well, I did.

    It turns out I actually had two copies of the entity overlapping, without knowing it.

    So in the attached version of this project I’ve duplicated that trick.

    This version actually looks close to what I need.

    Of course, just like deleting the entity each time isn’t a scalable solution for a project with tons of entities, making a new copy of the entity each time won’t scale either.

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober He’s not destroying the entity each time. CreateGround gets called once and ground is nil so the ground:destroy never gets called. Here’s the code with unused code removed. I like examples of things I’ve never used to be as small as possible so I’m not looking at unnecessary code.

    viewer.mode=FULLSCREEN
    
    function setup()
        scene = craft.scene()
        scene.camera.position=vec3(0,0,-4)
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
        bloom.threshold = 4
        bloom.intensity = 1.2
        bloom.softThreshold = 0.4
        bloom.iterations = 8
    
        material = craft.material(asset.builtin.Materials.Specular)
        material.map = readImage(asset.builtin.Surfaces.Desert_Cliff_Roughness)
    
        bloomMaterial = craft.material(asset.builtin.Materials.Basic)
        bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
        ground = scene:entity()
        ground.model = craft.model.cube(vec3(1,1,1))
        ground.position = vec3(0,0,0)    
        ground.material = material
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()
    end
    
    function touched(t)
        if t.state==BEGAN then
            gl=not gl
            if gl then
                ground.material = bloomMaterial
            else
                ground.material = material
            end
        end
    end
    
  • Posts: 977

    again, is this stuff written up anywhere?

  • Posts: 972

    Okay this is, I think, it. Or as close to it as I think I’ll get.

    The glow happens, though with only a verrrrry slight corona, and you can also see pretty clearly what skin the model is wearing.

    (I’d love to have a larger corona, but I couldn’t figure out a setting with a large corona that still left visible details on the model.)

    @dave1707 I get that you want to make things as simple as possible but sometimes that gives me less information than I need. For example, an unintended effect here is that for some reason these settings make the model semi-transparent. I would not have noticed that without the ability to rotate the model.

  • Posts: 972

    I’ll write up what I learned here in a little bit...

  • Posts: 972

    Ohhhhhhhh waitwaitwaitwait.

    For some reason, after a figure has a glow switched off, its chest becomes all caved-in.

    Darn it, now I’m lost again.

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober I want things I don’t know as simple as possible, that makes it easier to understand and see what’s happening. Once I understand that, then I can start adding more code in steps to try different things. For me that’s a lot easier then being shown a full blown program that does a lot of things and then try to figure out what code does what. For example, your program above shows the bloom effect in simple code whereas the AR Face example that shows the bloom is harder to figure out. At least it does for me. By reducing your code even further I was able to see exactly what was needed for the bloom.

  • Posts: 613

    @UberGoober to avoid the cave-in chest look, do not modify the blendMode.

  • Posts: 972

    @piinthesky if I don’t change the blend mode it looks like I don’t really get any glow, it just changes the color.

    I mean, gosh, I make the effect by applying a material, isn’t there just some easy way to remove a material?

  • dave1707dave1707 Mod
    edited April 14 Posts: 9,109

    @UberGoober Does this help. Tap screen to turn bloom on/off. The robot doesn’t have the sunken chest look.

    viewer.mode=STANDARD
    
    function setup()
        fill(255)
        parameter.integer("Rotate",-180,180,-180)
        scene = craft.scene()
        scene.camera.position=vec3(0,0,-40)
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
        bloom.threshold = 4
        bloom.intensity = 1.2
        bloom.softThreshold = 0.4
        bloom.iterations = 8
    
        material = craft.material(asset.builtin.Materials.Specular)
        material.map = readImage(asset.builtin.Blocky_Characters.RobotSkin)
    
        bloomMaterial = craft.material(asset.builtin.Materials.Basic)
        bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
        ground = scene:entity()
        ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
        ground.position = vec3(0,-5,0)
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function draw()
        update(DeltaTime)
        ground.eulerAngles = vec3(0,Rotate, 0)
        scene:draw()
        text("tap screen",WIDTH/2,HEIGHT-50)
    end
    
    function touched(t)
        if t.state==BEGAN then
            gl=not gl
            if gl then
                ground.material = bloomMaterial
            else
                ground.material = material
            end
        end
    end
    
  • dave1707dave1707 Mod
    edited April 14 Posts: 9,109

    @UberGoober Here's an example showing 50 robots at random positions. You can rotate or highlight individual robots using the pos, Rotate, int parameters. You can also rotate, zoom in/out the whole group.

    viewer.mode=STANDARD
    
    function setup()
        tab={}
        scene = craft.scene()
        scene.sun.rotation=quat.eulerAngles(30,45,30)
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 200, 0, 1000)
        v.ry=180
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
        bloom.threshold = 4
        bloom.intensity = 1.2
        bloom.softThreshold = 0.4
        bloom.iterations = 8
    
        material = craft.material(asset.builtin.Materials.Specular)
        material.map = readImage(asset.builtin.Blocky_Characters.RobotSkin)
    
        bloomMaterial = craft.material(asset.builtin.Materials.Basic)
        bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
        ground = scene:entity()
        ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
        ground.position = vec3(0,0,0)
    
        for z=1,50 do
            local ground = scene:entity()
            ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
            x=math.random(-50,50)
            y=math.random(-50,50)
            z=math.random(-50,50)
            ground.position = vec3(x,y,z)
            table.insert(tab,{gr=ground,x=x,y=y,z=z,r=0,a=false})
        end
        parameter.integer("pos",1,#tab,position)
        parameter.integer("Rotate",-180,180,0,rotate)
        parameter.boolean("int",false,intensity)
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function rotate()
        tab[pos].r=Rotate
    end
    
    function draw()
        update(DeltaTime)
        tab[pos].gr.eulerAngles = vec3(0,tab[pos].r, 0)
        scene:draw()
    end
    
    function position()
        Rotate=tab[pos].r
        int=tab[pos].a
    end
    
    function intensity()
        if int then
            tab[pos].gr.material = bloomMaterial
            tab[pos].a=true
        else   
            tab[pos].gr.material = material
            tab[pos].a=false
        end
    end
    
  • Posts: 972

    @dave1707 this is fantastic. I think I got hung up on what @Simeon said about being able to do it by just changing settings on the existing material, and I was trying to do everything without using two materials. But using two materials clearly works better.

  • Posts: 972

    Also @dave1707 I’m sorry I took a dig at your stripped-down-to-the-essentials code. You’re entirely right in your approach, I think.

  • Posts: 972

    @dave1707 there is one thing, when a model is switched off after it’s been glowing, its skin is noticeably lighter than it started. This is fixed if I set blendMode to NORMAL but that gets into the hollow-chest problem again.

  • dave1707dave1707 Mod
    edited April 15 Posts: 9,109

    @UberGoober I’m not sure what’s happening, but even before model #1 is switched on, I can see which Robot it is compared to the other ones.

    PS. The intensity function is being called when the program starts, that why the #1 Robot is lighter.

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober Try this update. I added ground.material=material to the for loop.

    viewer.mode=STANDARD
    
    function setup()
        tab={}
        scene = craft.scene()
        scene.sun.rotation=quat.eulerAngles(30,45,30)
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 200, 0, 1000)
        v.ry=180
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
        bloom.threshold = 4
        bloom.intensity = 1.2
        bloom.softThreshold = 0.4
        bloom.iterations = 8
    
        material = craft.material(asset.builtin.Materials.Specular)
        material.map = readImage(asset.builtin.Blocky_Characters.RobotSkin)
    
        bloomMaterial = craft.material(asset.builtin.Materials.Basic)
        bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
        ground = scene:entity()
        ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
        ground.position = vec3(0,0,0)
    
        for z=1,50 do
            local ground = scene:entity()
            ground.model= craft.model(asset.builtin.Blocky_Characters.Robot)
            ground.material=material
            x=math.random(-50,50)
            y=math.random(-50,50)
            z=math.random(-50,50)
            ground.position = vec3(x,y,z)
            table.insert(tab,{gr=ground,x=x,y=y,z=z,r=0,a=false})
        end
        parameter.integer("pos",1,#tab,position)
        parameter.integer("Rotate",-180,180,0,rotate)
        parameter.boolean("int",false,intensity)
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function rotate()
        tab[pos].r=Rotate
    end
    
    function draw()
        update(DeltaTime)
        tab[pos].gr.eulerAngles = vec3(0,tab[pos].r, 0)
        scene:draw()
    end
    
    function position()
        Rotate=tab[pos].r
        int=tab[pos].a
    end
    
    function intensity()
        if int then
            tab[pos].gr.material = bloomMaterial
            tab[pos].a=true
        else   
            tab[pos].gr.material = material
            tab[pos].a=false
        end
    end
    
  • edited April 15 Posts: 972

    I appreciate all the help you guys have been giving me, thanks.

    Still and all it's weird that I can't just do either thisEntity.material = nil or thisEntity.material:destroy() or thisEntity.remove(craft.material)...

  • Posts: 972

    @RonJeffries you are asking good questions about documentation.

    As much as I’d love more complete documentation, for the moment AFAIK we have only two options for finding better information of documented features, or for discovery of features not included at all in documentation:

    • Search the forums
    • Inspect the sample projects

    You’ll find many posts (not just by me) asking for clarification on how various features work, so it actually works out that the odds are good you can find, if not the exact information you want, something close.

    And if you can’t find what you need either of those ways, the only thing left to do is ask about it here.

  • Posts: 977

    yep

  • Posts: 972
    ...you know those insta-wikis that seem to be automatically generated for every game that’s ever come out ever? Do you think we could get them to do one on Codea? ;)
  • Posts: 613

    @UberGoober, an alternative approach for the bloom effect.

    -- bloom effect
    viewer.mode=STANDARD
    
    function setup()
        tab={}
        scene = craft.scene()
        scene.sun.rotation=quat.eulerAngles(30,45,30)
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 200, 0, 1000)
        v.ry=180
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
        bloom.threshold = 2
        bloom.intensity = 1
        bloom.softThreshold = 0.4
        bloom.iterations = 8
    
        for z=1,50 do
            local ground = scene:entity()
            ground.model= craft.model(asset.builtin.Blocky_Characters.Robot)
            ground.material=ground.model:getMaterial(0)
    
            x=math.random(-50,50)
            y=math.random(-50,50)
            z=math.random(-50,50)
            ground.position = vec3(x,y,z)
            table.insert(tab,{gr=ground,x=x,y=y,z=z,r=0,a=false})
        end
        parameter.integer("pos",1,#tab,position)
        parameter.integer("Rotate",-180,180,0,rotate)
        parameter.boolean("int",false,intensity)
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function rotate()
        tab[pos].r=Rotate
    end
    
    function draw()
        update(DeltaTime)
        tab[pos].gr.eulerAngles = vec3(0,tab[pos].r, 0)
        scene:draw()
    end
    
    function position()
        Rotate=tab[pos].r
        int=tab[pos].a
    end
    
    function intensity()
        if int then
            tab[pos].gr.material.diffuse = vec3(1.0,1.0,1.0)*3
            tab[pos].a=true
        else
            tab[pos].gr.material.diffuse =vec3(1.0,1.0,1.0)
            tab[pos].a=false
        end
    end
    
  • Posts: 972

    @piinthesky holy clock in a bobble-head, that’s exactly what I need!

    So the whole key to this is the line:

    ground.material=ground.model:getMaterial(0)

    ...which relies on the model:getMaterial function, which isn’t in the documentation (AFAIK) and which I don’t think anyone else knew existed.

    ...so if you don’t mind my asking, how did you know it existed?

    Since this is basically the answer to my question in another thread, I’m going to link to it there.

    Just in case you’re curious these are the bloom and diffuse values I think I’m gonna go with:


    bloom.threshold = 2.9 bloom.intensity = 0.58 bloom.softThreshold = 0.16 bloom.iterations = 8 ... tab[pos].gr.material.diffuse = vec3(2.5,1.5,4)
  • Posts: 972

    @piinthesky darrrrrrrrrrrrrrn.

    It works for the figure models but it doesn’t work for the others.

    See attached project.

  • Posts: 613

    @UberGoober, those models have multiple materials, so you have to loop over them all.

    -- bloom effect2
    viewer.mode=STANDARD
    
    function setup()
        bloomScale=5
    
        tab={}
        scene = craft.scene()
        scene.sun.rotation=quat.eulerAngles(30,45,30)
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 200, 0, 1000)
        v.ry=180
    
        cameraComponent = scene.camera:get(craft.camera)
        cameraComponent.hdr = true
        cameraComponent.colorTextureEnabled = true
    
        bloom = craft.bloomEffect()
        cameraComponent:addPostEffect(bloom)
    
        bloom.threshold = 2
        bloom.intensity = 0.65
        bloom.softThreshold = 0.2
        bloom.iterations = 8
    
        models = {asset.builtin.Blocky_Characters.Robot, asset.builtin.Blocky_Characters.WomanAlternative, asset.builtin.Watercraft.watercraftPack_005_obj, asset.builtin.CastleKit.siegeBallista_obj, asset.builtin.Watercraft.watercraftPack_007_obj,asset.builtin.SpaceKit.spaceCraft3_obj}
    
        for i=1,6 do
            local ground = scene:entity()
     --       ground.model= craft.model(models[math.random(#models)])
            ground.model= craft.model(models[i])
            x=math.random(-50,50)
            y=math.random(-50,50)
            z=math.random(-50,50)
            ground.position = vec3(x,y,z)
            table.insert(tab,{gr=ground,x=x,y=y,z=z,r=0,a=false})
        end
        parameter.integer("pos",1,#tab,position)
        parameter.integer("Rotate",-180,180,0,rotate)
        parameter.boolean("int",false,intensity)
    
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function rotate()
        tab[pos].r=Rotate
    end
    
    function draw()
        update(DeltaTime)
        tab[pos].gr.eulerAngles = vec3(0,tab[pos].r, 0)
        scene:draw()
    end
    
    function position()
        Rotate=tab[pos].r
        int=tab[pos].a
    end
    
    function intensity()
            thisModel=tab[pos].gr
            nMat=thisModel.model.submeshCount
    --        print(nMat)
            for i=0,nMat-1 do 
                thisMat=thisModel.model:getMaterial(i)
     --           print(thisMat.diffuse)
                if int then 
                    thisMat.diffuse=thisMat.diffuse*bloomScale
                else
                    thisMat.diffuse=thisMat.diffuse/bloomScale
                end
            end
            tab[pos].a=int
    end
    
  • edited April 19 Posts: 972

    @piinthesky I made a zip of your project, and gave it a nice icon, in case anyone wants to get it that way.

    Personally I like having icons, because otherwise I quickly end up with tons of little green squares that I can’t remember the purpose of.

    I also fixed the bug where the first entity had their skin made darker, which required abstracting your process into a stand-alone function, which was good to do anyway because it makes it easier to use for anyone who wants to cut and paste it.

    I also gave some of the variables verbose names, partly to help other coders grasp the code quicker, partly because that’s just me. :smiley:

    [edit: project wasn’t working, but should work now]

Sign In or Register to comment.