thothbot / parallax

Cross-platform Java 3D SDK
http://thothbot.github.io
MIT License
84 stars 26 forks source link

Image distortion #58

Open dev1intellial opened 8 years ago

dev1intellial commented 8 years ago

I am drawing 3D shape using parallax library. I have use MeshLambertMaterial to draw this shape but image is not showing properly.

lvlkl

I have used antiliasing true but still problem is there. What are the possibilities cause for this type of issue?

I have used below code :

private Line getLine(Geometry geometry) {
if (line  == null) {
  line = new Line(geometry, getLineMaterial());      
  line.getRotation().set(-1.58, 0, -6.3);
  line.getScale().set(1);
  }
 return line;
}

private LineBasicMaterial getLineMaterial() {
if (lineMaterial == null) {
  lineMaterial = new LineBasicMaterial();
}
 return lineMaterial;
}

private Mesh getMesh(Geometry geometry) {
if (mesh == null) {
  mesh = new Mesh(geometry, getMeshMaterial());
  mesh.getRotation().set(-1.58, 0, -6.3); 
  mesh.getScale().set(1);
  }

return mesh;
}

private MeshLambertMaterial getMeshMaterial() {
if (meshMaterial == null) {
  meshMaterial = new MeshLambertMaterial();
  meshMaterial.setShading(Material.SHADING.FLAT);
  meshMaterial.materialNeedsSmoothNormals();
  meshMaterial.setReflectivity(50);
}

 return meshMaterial;
}

private Object3D getObject3D() {
if (object3D == null) {
  object3D = new Object3D();  
  object3D.getPosition().setY(48);
  if (topView) { 
    if (xAngle == 0 && yAngle == 0) {
      if (doAnimate) object3D.getRotation().set(-0.25, 0.26, 0);
      else object3D.getRotation().set(0.00, 0.0, 0);
    }
    else object3D.getRotation().set(xAngle, yAngle, 0);
  }
  else { 
    object3D.getRotation().set(0.321, 0.26, 0);
  }
}
  return object3D;
} 

long start = 0;

@Override
protected void onStart() {    
start = System.currentTimeMillis();
drawShape();
double camPositionX = 0;

if (yValue == 0) camPositionY = (45  + (elementPosition / 2));
else camPositionY = (45  + (elementPosition / 2)) - yValue;

if (xValue == 0) camPositionX = 0;
else if (xValue > 0) camPositionX = 110 + xValue;
else camPositionX = 0 + xValue;

getCamera().getPosition().set(camPositionX, camPositionY, camPositionZ);  
getScene().add(getHemisphereLight());
getScene().add(getDirectionalLightTop());
getScene().add(getDirectionalLightBottom());
}

@Override
protected void onUpdate(double duration) {
if (doAnimate) {
  double topX = 0.2 * 0.0321;
  double topY = 0.2 * 0.026;      

  if (getObject3D() != null) {
    if (topView) {
      if (getDoubleValue(getObject3D().getRotation().getX(), 2).equals("0.32")) {
        xTopRotation = true;
        doRender = true;
      }

      if (getDoubleValue(getObject3D().getRotation().getY(), 2).equals("0.26")) {
        yTopRotation = true;
      }

      if (!xTopRotation ) {
        if (!getDoubleValue(getObject3D().getRotation().getX(), 2).equals("0.32") ) {
          getObject3D().getRotation().addX( topX );
          topX += topX;
        }
      }

      if (!yTopRotation) {
        if (!getDoubleValue(getObject3D().getRotation().getY(), 2).equals("0.26")) {
          getObject3D().getRotation().addY(topY);
          topY += topY;
        }
      }
    }
    else {
      double bottomX = 0.2 * 0.0321;

      if (getDoubleValue(getObject3D().getRotation().getX(), 2).equals("-.25") ) {
        xBottomRotation = true;
        doRender = true;
      }

      if (!xBottomRotation) {    
        if (!getDoubleValue(getObject3D().getRotation().getX(), 2).equals("-.25") ) {
          getObject3D().getRotation().addX(-bottomX ); 
          bottomX += bottomX;
        }
      }
    }
  }    
}

if (!doRender && doAnimate) {
  getRenderer().clear();
  getRenderer().render(getScene(), getCamera());
}
else if (genRender == 0) {
  genRender ++;
  getRenderer().clear();
  getRenderer().render(getScene(), getCamera());
}
}   
}

   // For rendering panel Used below code : 
    renderingPanel = new RenderingPanel();
    renderingPanel.setSize(370+"px", 236+"px");
    renderingPanel.setBackground(0x000000);
    renderingPanel.addCanvas3dErrorHandler(this);
    renderingPanel.addSceneLoadingHandler(this);
    renderingPanel.setAnimatedScene(new ThreeDImage(getCanvasPanel().getElement(), "4", "1.55", "18", "18", "Green", "White", "Green", "White", "AnyLF", topView, 0, 0, 0.321, 0.26, "No", "No"));

   //getCanvasPanel().clear();
   getCanvasPanel().add(getImagePanel());
   getCanvasPanel().add(renderingPanel);
   RootPanel.get("image").add(getMainPanel());

The main issue is that when Object position is (0, 0, 0) but when position is changing then image is not rotating correctly. Means image is going to distorted when object is rotating. Tha main issue coming form onStart() , onUpdate() and getObject3D() method.

thothbot commented 8 years ago

Can you attach your code and an image

thothbot commented 8 years ago

Thank you for your report, I'll investigate and let you know

thothbot commented 8 years ago

Just tested image map, didn't find any issues in regular case.

Your code is too large. Can you please paste in which part of your code you have an issue. (Which object, material and texture. and attach texture also, because it can be a not power of two).