Should Setcolor Change Color Of All 3d Worlds?

Discussion in 'Buildbox 3.0' started by DanFarfan, Oct 3, 2018.

  1. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    BB API says clearly..

    setTexture( name )
    Will apply new texture to all 3DModel Components.

    While no such statement is made wrt color, if setColor() doesn't change color of all 3D Worlds, how can we change the color (using Javascript code, of course), for example, of the cue ball in the slingshot asset?

    The following doesn't work as desired.
    let ss = this.scene().find("SlingshotYellow")[0];
    let ss_color = ss.color();
    log(`start color = (${ss_color.r},${ss_color.g},${ss_color.b})`);
    ss.setColor(14,28,100); // no visible change on screen
    log(`start color = (${ss_color.r},${ss_color.g},${ss_color.b})`); // shows (14,28,100)

    Seems the setColor commands is changing only the 3D World w/ the "platform" mesh, not the sphere mesh.
    The sphere mesh is what defines the color that the cueball appears on the screen. (its Material is set to Default).

    Any ideas for a workaround? How do we address the correct 3D World to change its color?

    By the way, for those of you at home keeping score... the color of a 3D Model marked "shadeless transparent" is, of course, ignored.. or at least not visible on the screen because, it's transparent!

    Thanks
    @DanFarfan
     
  2. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    I think something wrong in the Slingshot Template. If you try in a fresh project or Float Template then you can change the color of the objects at runtime.
     
  3. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    I think it is problem due to two models in the Slingshot Object. You can try by change the model color in touch begin, it works.
    //----Touches
    function touchBegan( point ){
    _startPoint = point;
    let model = this.entity().component('Ball 3D Model');
    model.setColor(255,0,0);
     
  4. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    Well, float doesn't exhibit the problem because it only has one 3D Model. Not similar.
     
  5. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42

    THIS is closer. But, I discovered the hard way that 3D World components have .setColor() function, but not color(). I need to be able to read current color value and set the color.

    Error message on:
    let model_color = model.color();
    is
    TypeError: model.color is not a function
     
  6. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    Okay. It solves the set colour issue with a workaround that you expecting. Yes, Get property is not implemented for many components.
    Example: there is addScorePoint but no getScorePoint.
    We have to wait for the next release. If we have sufficient time, the Beta build is challenging and interesting for developers to report and get it done earlier.
     
  7. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    Yes. Good example. IMO, we need the scoring feature of BB3 to be completely redesigned.

    However, I realized I can accomplish what I want regarding color setting and getting!

    In short, the answer is set the color twice. Once to change what we see on the screen and the second time so the program can check what the current color is and act accordingly. #lookingForwardToNextUpgrade.


    const _f = "Slingshot.ColorHelp";
    var _enabled = false;

    function _log(str) {
    log(str);
    }

    function init(){
    } // init


    function update(dt){
    } // update



    function signal(name, value){
    const f = `${_f}.signal`;
    _enabled = value;
    _log(`${f} ${name} ${value}`);
    } // signal



    //
    // 2 helper functions
    //

    function setColor(r,g,b) {
    // for slignshot (at least) setting entity color
    // changes color on the transparent world only
    // i.e. doesn't change the visible cueball
    //
    // BUT this.entity().color() does work,
    // use this.entity().setColor(r,g,b) so the current color can be read

    this.entity().setColor(r,g,b);
    // this changes the color of the model that
    // IS visible on the screen.
    let model = this.entity().component('3D Model');
    model.setColor(r,g,b);
    } // set color
    component.setColor = setColor;


    // return the color
    function color() {
    return ( this.entity().color() );
    } // color
    component.color = color;
     
  8. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    If we want to access at the different node code then I thought exactly the same.

    If colour changing logic happening in one javascript node then it is just easier to assign in a currentColor variable and check again.

    var _currentColor;
     
  9. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    True.

    I'm still getting my head wrapped around how scoping works (and doesn't, so far).
     

Share This Page