Ignore:
Timestamp:
03/23/14 12:52:58 (10 years ago)
Author:
mmichalski
Message:

Examples how to open creatues by viewer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • js/viewer-f0/js/graphicsEngine.js

    r143 r188  
    1 function GraphicsEngine() {
     1function GraphicsEngine(context) {
    22    this._scene = undefined;
    33    this._camera = undefined;
    44    this._renderer = undefined;
    5     this._canvasWidth = 500;
    6     this._canvasHeight = 500;
    7     this._containerContext = undefined;
     5    this._canvasWidth = 400;
     6    this._canvasHeight = 400;
     7    this._containerContext = context;
    88    this._BALL_RADIUS = 0.25;
    99    this._controls = undefined;
     
    2121    this._renderer.setClearColor(0x000000, 1);
    2222    this._renderer.setSize(this._canvasWidth, this._canvasHeight);
    23     this._containerContext = $("#container");
     23    //this._containerContext = $("#container");
    2424    this._containerContext.append(this._renderer.domElement);
    2525}
     
    4343GraphicsEngine.prototype._rotateObject = function (object, part) {
    4444    object.rotateX(part.getXrot());
    45     object.rotateY(part.getYrot());
     45    object.rotateY(-part.getYrot());
    4646    object.rotateZ(part.getZrot());
    4747}
     
    7474}
    7575
     76GraphicsEngine.prototype._debugShow = function(object)
     77{
     78    var pos = object.position;
     79    var scale = object.scale;
     80    var rot = object.rotation
     81    //console.log(pos.x, pos.y, pos.z , "|", rot.x, rot.y, rot.z,"|", scale.x, scale.y, scale.z);
     82}
     83
    7684GraphicsEngine.prototype._addEllipsoid = function (part) {
    7785    var geometry = new THREE.SphereGeometry(1, 20, 20);
    78     geometry.applyMatrix(new THREE.Matrix4().makeScale(part.getXshape(), part.getYshape(), part.getZshape()));
    79 
    8086    var ellipsoidMaterial = new THREE.MeshPhongMaterial({color: 0xffffff});
    8187    ellipsoidMaterial.color.setRGB(part.getR(), part.getG(), part.getB())
    8288
    8389    var ellipsoid = new THREE.Mesh(geometry, ellipsoidMaterial);
     90    ellipsoid.scale.set(part.getXshape(), part.getYshape(), part.getZshape())
    8491    ellipsoid.position.set(part.getX(), part.getY(), part.getZ());
    8592    this._rotateObject(ellipsoid, part);
     
    8895    if(this._showAxis)
    8996        ellipsoid.add(new THREE.AxisHelper(1));
     97
    9098    this._scene.add(ellipsoid);
    9199}
     
    93101GraphicsEngine.prototype._addCylinder = function (part) {
    94102    var geometry = new THREE.CylinderGeometry(1, 1, 1, 10, 10, false);
    95     geometry.applyMatrix(new THREE.Matrix4().makeScale(part.getZshape(), part.getXshape(), part.getYshape()));
    96103
    97104    var material = new THREE.MeshLambertMaterial({color: 0xffffff});
     
    99106
    100107    var cylinder = new THREE.Mesh(geometry, material);
     108
     109    cylinder.scale.set(part.getXshape(), part.getYshape(), part.getZshape())
    101110    cylinder.position.set(part.getX(), part.getY(), part.getZ());
    102     cylinder.overdraw = true;
    103111    this._rotateObject(cylinder, part);
    104112
    105113    this._parts.push(cylinder);
    106114    if(this._showAxis)
    107         cylinder.add(new THREE.AxisHelper(1));
     115        cylinder.add(new THREE.AxisHelper(5));
     116
    108117    this._scene.add(cylinder);
     118
    109119}
    110120
    111121GraphicsEngine.prototype._addCuboid = function (part) {
    112122    var geometry = new THREE.CubeGeometry(2, 2, 2, 10, 10, 10);
    113     geometry.applyMatrix(new THREE.Matrix4().makeScale(part.getXshape(), part.getYshape(), part.getZshape()));
     123    //TODO: poprawić getXshape na getXscale
    114124
    115125    var material = new THREE.MeshLambertMaterial({color: 0xffffff});
     
    117127
    118128    var cube = new THREE.Mesh(geometry, material);
     129    cube.scale.set(part.getXshape(), part.getYshape(), part.getZshape())
    119130    cube.position.set(part.getX(), part.getY(), part.getZ());
    120131    this._rotateObject(cube, part);
     
    127138
    128139GraphicsEngine.prototype.addPart = function (part) {
     140    console.log(part.getX(),part.getY(),part.getZ(), "|", part.getXshape(),part.getYshape(),part.getZshape(),"|",part.getXrot(),part.getYrot(),part.getZrot())
    129141    switch (part.getType()) {
    130142        case 0:
     
    196208
    197209        copy.rotateX(joint.getXrot());
    198         copy.rotateY(joint.getYrot());
     210        copy.rotateY(-joint.getYrot());
    199211        copy.rotateZ(joint.getZrot());
    200212
     
    233245    this._controls = new THREE.TrackballControls(this._camera, this._renderer.domElement)
    234246    this._debug();
     247
     248
     249
    235250}
    236251
     
    255270GraphicsEngine.prototype.debugTest = function()
    256271{
    257 
    258 }
    259 
     272    for(var i = 0; i < this._parts.length; i++)
     273        this._debugShow(this._parts[i]);
     274}
     275
Note: See TracChangeset for help on using the changeset viewer.