Ignore:
Timestamp:
08/25/24 01:56:48 (11 months ago)
Author:
Maciej Komosinski
Message:

Updated standard.expdef animated demo: uses the most recent Framsticks SDK, supports 6 genetic encodings, adjustable mutation and crossover probabilities, shows colored genotypes, allows user to manually increase/decrease fitness of the current individual, displays its neural network

Location:
js/standard_expdef_demo/js/world
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • js/standard_expdef_demo/js/world/core.js

    r880 r1326  
    1717    this.sky = this.Sky();
    1818    this.sun = this.Sun();
    19     this.table = this.Table();
    2019  }
    2120
     
    2524    texture.repeat.set(Config.Ground.REPEAT, Config.Ground.REPEAT);
    2625    texture.anisotropy = Config.Ground.ANISOTROPY;
     26        texture.colorSpace = THREE.SRGBColorSpace;
    2727
    28     let geometry = new THREE.PlaneBufferGeometry(Config.Ground.WIDTH, Config.Ground.WIDTH);
     28    let geometry = new THREE.PlaneGeometry(Config.Ground.WIDTH, Config.Ground.WIDTH);
    2929    let material = new THREE.MeshLambertMaterial({map: texture});
    3030    let ground = new THREE.Mesh(geometry, material);
     
    3636  }
    3737
    38   Table() {
    39     let table = new Table(Config.Simulation.GENOTYPES);
     38  createTable(genotypes,genotypeEncoding){
     39        this.table = this.Table(genotypes,genotypeEncoding);
     40  }
     41
     42  setGenotypes(genotypes, genotypeEncoding){
     43        this.table.genotypes = genotypes;
     44        for (let i = 0; i < this.table.genotypes.length; i++) {
     45                this.scene.remove(this.table.genotypePlanks[i].textMesh);
     46                // this.table.genotypePlanks[i] = new GenotypePlank(genotypes[i],genotypeEncoding,i);
     47                this.table.genotypePlanks[i].updateGenotype(genotypes[i],genotypeEncoding);
     48                this.scene.add(this.table.genotypePlanks[i].textMesh);
     49                this.table.fitnessPlanks[i].updateFitness((Math.random() * 100).toFixed(2));
     50        }
     51  }
     52
     53  Table(genotypes,genotypeEncoding) {
     54    let table = new Table(genotypes,genotypeEncoding);
    4055    this.scene.add(table.board);
    4156    this.scene.add(table.genotypeHeader.mesh);
     
    7691
    7792  Sky() {
    78     let sky = new THREE.Sky()
     93    let sky = new Sky()
    7994    sky.scale.setScalar(Config.Sky.SCALE);
    8095    sky.material.uniforms.turbidity.value = Config.Sky.TURBIDITY;
    8196    sky.material.uniforms.rayleigh.value = Config.Sky.RAYLEIGH;
    82     sky.material.uniforms.luminance.value = Config.Sky.LUMINANCE;
     97        // sky.material.uniforms.luminance.value = Config.Sky.LUMINANCE;
    8398    sky.material.uniforms.mieCoefficient.value = Config.Sky.MIE_COEFFICIENT;
    8499    sky.material.uniforms.mieDirectionalG.value = Config.Sky.MIE_DIRECTIONAL_G;
     
    89104  Sun() {
    90105    let sun = new THREE.Mesh(
    91       new THREE.SphereBufferGeometry(Config.Sun.RADIUS, Config.Sun.WIDTH_SEGMENTS, Config.Sun.HEIGHT_SEGMENTS),
     106      new THREE.SphereGeometry(Config.Sun.RADIUS, Config.Sun.WIDTH_SEGMENTS, Config.Sun.HEIGHT_SEGMENTS),
    92107      new THREE.MeshBasicMaterial({color: Config.Sun.COLOR})
    93108    );
  • js/standard_expdef_demo/js/world/object/arrow.js

    r880 r1326  
    2222    let material = new THREE.MeshLambertMaterial({map: texture});
    2323    material.opacity = 0;
    24     material.blending = THREE.NoBlending;
     24    // material.blending = THREE.NoBlending;
    2525
    2626    this.mesh = new THREE.Mesh(geometry, material);
  • js/standard_expdef_demo/js/world/object/framstick.js

    r880 r1326  
    112112    }
    113113
    114     let model = new Module.Model(genoObj, true);
     114    let model = new Module.Model(genoObj, Module.Model["SHAPETYPE_UNKNOWN"], true);
     115        model.open();
     116        model.close();
    115117    Module.destroy(stringObj);
    116118    Module.destroy(genoObj);
  • js/standard_expdef_demo/js/world/object/table.js

    r880 r1326  
    1010   */
    1111
    12   constructor(genotypes) {
    13     this.genotypes = genotypes
     12  constructor(genotypes,genotypeType) {
     13    this.genotypes = genotypes;
     14        this.genotypeType = genotypeType;
    1415
    1516    this.board = this.Board();
     
    2526    texture.repeat.set(Config.Table.Board.REPEAT, Config.Table.Board.REPEAT);
    2627    texture.anisotropy = Config.Table.Board.ANISOTROPY;
     28        texture.colorSpace = THREE.SRGBColorSpace;
    2729
    2830    let geometry = new THREE.BoxGeometry(Config.Table.Board.WIDTH,
     
    3234    let material = new THREE.MeshLambertMaterial({map: texture});
    3335    material.opacity = 0;
    34     material.blending = THREE.NoBlending;
     36    // material.blending = THREE.NoBlending;
    3537
    3638    let board = new THREE.Mesh(geometry, material);
     
    4648    let planks = []
    4749    for (let i = 0; i < this.genotypes.length; i++) {
    48       planks.push(new GenotypePlank(this.genotypes[i], i));
     50      planks.push(new GenotypePlank(this.genotypes[i],this.genotypeType, i));
    4951    }
    5052    return planks
     
    6062
    6163  GenotypeHeader() {
    62     return new GenotypePlank("Genotype", this.genotypes.length, true)
     64    return new GenotypePlank("Genotype",this.genotypeType, this.genotypes.length, true)
    6365  }
    6466
     
    7173class GenotypePlank {
    7274
    73   constructor(genotype, position, bold) {
     75  constructor(genotype, genotypeEncoding, position, bold) {
    7476    this.genotype = genotype;
    7577    this.position = {
     
    8385    texture.repeat.set(Config.Table.GenotypePlank.REPEAT, Config.Table.GenotypePlank.REPEAT);
    8486    texture.anisotropy = Config.Table.GenotypePlank.ANISOTROPY;
     87        texture.colorSpace = THREE.SRGBColorSpace;
    8588
    8689    let geometry = new THREE.BoxGeometry(Config.Table.GenotypePlank.WIDTH,
     
    9497    this.mesh.receiveShadow = Config.Table.GenotypePlank.RECEIVE_SHADOW;
    9598
    96     this.textMesh = Text.getGenotypeMesh(this.genotype.replace("/*4*/ ", ""));
     99        this.genotypeType = genotypeEncoding;
     100    this.textMesh = Text.getGenotypeMesh(this.genotype,this.genotypeType);
    97101    if (bold == true) {
    98       this.textMesh = Text.getFitnessMesh(this.genotype.replace("/*4*/ ", ""));
     102      this.textMesh = Text.getFitnessMesh(this.genotype.replace(`${this.genotypeType} `, ""));
    99103    }
    100104    this.textMesh.position.set(this.position.x, this.position.y, this.position.z + 1);
     105  }
     106
     107  updateGenotype(genotype,genotypeType){
     108        this.genotype = genotype;
     109        this.genotypeType = genotypeType;
     110        this.textMesh = Text.getGenotypeMesh(this.genotype,this.genotypeType);
     111        this.textMesh.position.set(this.position.x, this.position.y, this.position.z + 1);
    101112  }
    102113
     
    137148    texture.repeat.set(Config.Table.FitnessPlank.REPEAT, Config.Table.FitnessPlank.REPEAT);
    138149    texture.anisotropy = Config.Table.FitnessPlank.ANISOTROPY;
     150        texture.colorSpace = THREE.SRGBColorSpace;
    139151
    140152    let geometry = new THREE.BoxGeometry(Config.Table.FitnessPlank.WIDTH,
     
    150162    this.textMesh = Text.getFitnessMesh(this.fitness);
    151163    this.textMesh.position.set(this.position.x, this.position.y, this.position.z + 1);
     164  }
     165
     166  updateFitness(value){
     167        this.fitness = value;
     168        this.textMesh.element.innerHTML = roundNumber(this.fitness,2);
    152169  }
    153170
  • js/standard_expdef_demo/js/world/object/text.js

    r880 r1326  
    66
    77var Text = {
    8   getGenotypeMesh: function(genotype) {
     8        styleRegex: /<style>.*<\/style>/,
     9        numberRegex : /-?\d+(\.\d+)?/g,
     10        roundMatch: function(match) {
     11        return roundNumber(match,2).toString();
     12    },
     13
     14  getGenotypeMesh: function(genotype,genotypeType) {
     15        const genman = new Module.GenMan();
     16        genotype = genotype.replace(this.numberRegex, this.roundMatch);
     17        genotype = genotype.replaceAll("\n","⤶");
    918    if (genotype.length > 20) {
    10       genotype = genotype.slice(0, 20) + "..."
     19       genotype = genotype.slice(0,30) + "..."
    1120    }
    1221    var element = document.createElement("div");
    13     element.className = "genotype";
    14     element.textContent = genotype;
    15     return new THREE.CSS3DObject(element);
     22    element.innerHTML = genman.HTMLize(genotype).c_str();
     23        element.innerHTML = element.innerHTML.replace(this.styleRegex,"").replace(genotypeType,"");
     24        Module.destroy(genman);
     25    return new CSS3DObject(element);
    1626  },
    1727
     
    2030    element.className = "fitness";
    2131    element.textContent = fitness;
    22     return new THREE.CSS3DObject(element);
     32    return new CSS3DObject(element);
    2333  },
    2434
     
    2737    element.className = "info";
    2838    element.textContent = info;
    29     return new THREE.CSS3DObject(element);
     39    return new CSS3DObject(element);
    3040  }
    3141}
Note: See TracChangeset for help on using the changeset viewer.