1.4.3 • Published 6 years ago

greljs v1.4.3

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

grel

Jun 20, 2018

- Basic demo

let code = `
class C() {
    // header code
    float outVal = 0.0;

    // onInputArg code
    onInputArg(inputArg) {
        if(inputArg instanceOf A) {

        }
        if(inputArg==a) {
            outVal = inputArg0;
        }
    }

    // main code
    main() {
        foutput0 = outVal;
    }
}

A a = new A(0.0);
A b = new A(0.0);
C c = new C();`;

grels = new GRelScript({"code": code});

let render = function() {
    grels.tick();
    requestAnimFrame(render);
};
render();
}

A a = new A(0.0);
a.setPosition(0.1, 1.0, 0.0, 1.0);
A b = new A(0.0);
C c = new C();`;
}

A a = new A(0.0);
a.setDestination(0.1, 1.0, 0.0, 1.0);
A b = new A(0.0);
C c = new C();`;
grels = new GRelScript({"code": code,
                        "meshes": [ "../_RESOURCES/meshA.obj"]});
let code = `
class A() {
    onDrawVertex() {
        if(meshId == 0.0) {
            nodeVertexColor = vec4(0.0, 1.0, 0.0, 1.0);
        }
    }
}
class B() {
    onDrawVertex() {
        if(meshId == 1.0) {
            nodeVertexColor = vec4(1.0, 0.0, 0.0, 1.0);
        }
    }
}
class C() {
    float outVal = 0.0;

    onInputArg(inputArg) {
        if(inputArg instanceOf A) {
            outVal = inputArg0;
        }
    }

    onDrawVertex() {
        if(meshId == 2.0) {
            nodeVertexPosition = vec4(nodeVertexPosition.x*0.4, nodeVertexPosition.y*0.4, nodeVertexPosition.z*0.4, 1.0);
            if(foutput0 > 0.0) {
                nodeVertexColor = vec4(0.0, 1.0, 0.0, 1.0);
            } else {
                mat4 mm = rotationMatrix(vec3(1.0,0.0,0.0), (3.1416/2.0)*2.0);
                nodeVertexPosition = nodeVertexPosition*mm;

                nodeVertexColor = vec4(1.0, 0.0, 0.0, 1.0);
            }
        }
    }
                
    main() {
        foutput0 = outVal;
    }
}

A a = new A(0.0);
B b = new B(0.0);
C c = new C();`;

grels = new GRelScript({"code": code,
                        "meshes": [ "../_RESOURCES/meshA.obj",
                                    "../_RESOURCES/meshB.obj",
                                    "../_RESOURCES/meshC.obj"]});

- Logic outside class

float rr = 0.3;
float rrb = 0.3;
float rrc = 0.0;
AB arr[10];
AB arrB[10];
AB arrC[10];
A d = new A(0.2); d.setPosition(-10.0, 0.0, 10.0, 1.0);
for(int n=0;n<3;n++) {
    arr[n] = 0.31+rr; // (it generate extra code. better use it with care)
    arr[n] = 0.27+rr+d;
}
for(int n=0;n<5;n++) {
    rrc = rrc+0.1;
    arrB[n] = 0.51+rrc;
}
for(int n=0;n<10;n++) {
    arr[n].setPosition(-100.0, 0.0, float(n), 1.0); // initial position (setPosition method does not extra code generation)
    arrB[n].setPosition(-70.0, 0.0, float(n), 1.0); // initial position
    arrC[n].setPosition(-30.0, 0.0, float(n), 1.0); // initial position
    arrC[n] = arr[n]+arrB[min(n+2,9)]; // CPU?. it's executed in GPU under the hood! :P (but is better use classes for it)
}
arr[0] = new AB(0.3);
A a = new A(0.0); a.setPosition(-10.0, 0.0, -10.0, 1.0);
A b = new A(0.0); b.setPosition(-10.0, 0.0, -5.0, 1.0);
A c = new A(0.3); c.setPosition(-10.0, 0.0, 5.0, 1.0);

C e = new C(); e.setPosition(10.0, 0.0, -10.0, 1.0);
F f = new F(); f.setPosition(10.0, 0.0, -5.0, 1.0);
F fb = new F(); fb.setPosition(10.0, 0.0, 5.0, 1.0);
F fc = new F(); fc.setPosition(10.0, 0.0, 10.0, 1.0);
F fd = new F(); fd.setPosition(10.0, 0.0, 20.0, 1.0);
F ff = new F(); ff.setPosition(10.0, 0.0, 30.0, 1.0);

A a2 = new A(0.0); a2.setPosition(-10.0, 0.0, 40.0, 1.0);
F f2 = new F(); f2.setPosition(10.0, 0.0, 40.0, 1.0);

c = d;             // set GFunction c with GFunction d (c is the same as c[0] or c.foutput0 (0-4))
e = d;             // set GFunction e with GFunction d
fd = rrb;          // set GFunction fd with real variable rrb
if(a > d) {        // compare two GFunction floats
    e = c;         // set GFunction e with GFunction c
    if(b > 0.5) {  // compare GFunction float with real number
        f = a;     // set GFunction f with GFunction a
        fb = rr;   // set GFunction fb with real variable rr
        fc = 0.4;  // set GFunction fc with real number
        rrb = 0.6; // set real var rrb with real number
        fd = rrb;  // if this is commented fd will keep with initial 0.3 of rrb
    }
}

if(a > 0.0 && a2 > 0.5) {
    f2 = 1.0;
}

// for less internal code you should use the onInputArg event inside classes with an "instanceOf" and
// to handle it in a general form and set the "foutput" depending of status of the input arguments.
ff.onInputArg((inputArg) => { // (it generate much extra code. Use it with care)
    if(inputArg==fd) {
        if(inputArg0 > 0.4) {
            foutput0 = 1.0/2.0;
        }
    }
});

- Two custom geometries with independent logic over one node

- Quantum simulator (in progress)

inputArg - (to use with: (inputArg instanceof node_type)(checked with internal inputArgNodeType) OR with: (inputArg == node_name)(checked with internal inputArgNodeName) inputArg0 inputArg1 inputArg2 inputArg3 inputArg4

WRITE:

foutput0 foutput1 foutput2 foutput3 foutput4

READ-WRITE:

currentPos

WRITE:

foutput0 foutput1 foutput2 foutput3 foutput4

READ-WRITE:

currentPos

foutput0 foutput1 foutput2 foutput3 foutput4 meshId

READ-WRITE:

nodeVertexPosition nodeVertexColor currentPosition

npm install greljs
<script src="../../dist/grel/GRel.class.js"></script>
OR
<script src="../../dist/gbrain/grel.min.js"></script>

Slack Group

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.40

6 years ago

1.2.39

6 years ago

1.2.38

6 years ago

1.2.37

6 years ago

1.2.36

6 years ago

1.2.35

6 years ago

1.2.34

6 years ago

1.2.33

6 years ago

1.2.32

6 years ago

1.2.31

6 years ago

1.2.30

6 years ago

1.2.29

6 years ago

1.2.28

6 years ago

1.2.27

6 years ago

1.2.26

6 years ago

1.2.25

6 years ago

1.2.24

6 years ago

1.2.23

6 years ago

1.2.22

6 years ago

1.2.21

6 years ago

1.2.20

6 years ago

1.2.19

6 years ago

1.2.18

6 years ago

1.2.17

6 years ago

1.2.16

6 years ago

1.2.15

6 years ago

1.2.13

6 years ago

1.2.12

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.0.29

6 years ago

0.0.282

6 years ago

0.0.281

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.261

6 years ago

0.0.26

6 years ago

0.0.257

6 years ago

0.0.256

6 years ago

0.0.255

6 years ago

0.0.254

6 years ago

0.0.253

6 years ago

0.0.252

6 years ago

0.0.251

6 years ago

0.0.25

6 years ago

0.0.249

6 years ago

0.0.248

6 years ago

0.0.247

6 years ago

0.0.246

6 years ago

0.0.245

6 years ago

0.0.244

6 years ago

0.0.243

6 years ago

0.0.242

6 years ago

0.0.241

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.223

6 years ago

0.0.222

6 years ago

0.0.221

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago