public void selectObject(
      Object3D target, int mouseX, int mouseY, int screenWidth, int screenHeight, Camera camera) {
    try {
      selectedDraggablekObject = target;
      Ray ray = projector.gwtCreateRay(mouseX, mouseY, screenWidth, screenHeight, camera);

      // ig dry every thing dont work
      // Vector3
      // rotation=GWTThreeUtils.rotationToVector3((selectedDraggablekObject.getMatrixWorld()));
      // mouseClickCatcher.getRotation().copy(rotation);

      selectedDraggablekObject.updateMatrixWorld(true);
      mouseCatchPlane
          .getPosition()
          .copy(GWTThreeUtils.toPositionVec(selectedDraggablekObject.getMatrixWorld()));
      mouseCatchPlane.updateMatrixWorld(true); // very important

      JsArray<Intersect> pintersects = ray.intersectObject(mouseCatchPlane);
      draggableOffset.copy(pintersects.get(0).getPoint()).subSelf(mouseCatchPlane.getPosition());
      /*
       * make a problem?
      if(draggableOffset.getX()<0.0001){
      	draggableOffset.setX(0);
      }
      if(draggableOffset.getY()<0.0001){
      	draggableOffset.setY(0);
      }
      if(draggableOffset.getZ()<0.0001){
      	draggableOffset.setZ(0);
      }
      */

    } catch (Exception e) {
      LogUtils.log("selectObject:" + e.getMessage());
      selectedDraggablekObject = null;
    }
    // LogUtils.log("offset:"+ThreeLog.get(draggableOffset));
  }
  /*
   *** sometime it error happend,check
   * double mouseMoved=(Math.abs(diffX)+Math.abs(diffY));
   *double length=newPos.clone().subSelf(getCurrentIkData().getTargetPos()).length();
   *  if(length<mouseMoved*5){
   */
  public Vector3 moveSelectionPosition(
      int mouseX, int mouseY, int screenWidth, int screenHeight, Camera camera) {
    if (isSelected()) {
      try {
        Ray ray = projector.gwtCreateRay(mouseX, mouseY, screenWidth, screenHeight, camera);
        JsArray<Intersect> intersects = ray.intersectObject(mouseCatchPlane);

        Vector3 newPos = intersects.get(0).getPoint().subSelf(draggableOffset);
        log = "newPos-raw:" + ThreeLog.get(newPos);
        Vector3 parentPos = THREE.Vector3();
        if (selectedDraggablekObject.getParent() != null) {
          // selectedDraggablekObject.getParent().updateMatrixWorld(true); //if call it bone moving
          // will be broken.i have no idea.
          parentPos =
              GWTThreeUtils.toPositionVec(selectedDraggablekObject.getParent().getMatrixWorld());
          // LogUtils.log("parent:"+ThreeLog.get(parentPos));
          log += "parentPos:" + ThreeLog.get(parentPos);
        }
        newPos.subSelf(parentPos);

        Matrix4 rotM = THREE.Matrix4();
        Vector3 rotation =
            GWTThreeUtils.rotationToVector3(
                (selectedDraggablekObject.getParent().getMatrixWorld()));
        // rotM.getInverse(selectedDraggablekObject.getMatrixRotationWorld());

        log += "parentRot:" + ThreeLog.get(GWTThreeUtils.radiantToDegree(rotation));
        rotM.getInverse(GWTThreeUtils.rotationToMatrix4(rotation));

        rotM.multiplyVector3(newPos);

        // Vector3 parentRotation=THREE.Vector3();

        /*
        Object3D obj=selectedDraggablekObject;
        while(obj.getParent()!=null){
        	parentPos.addSelf(obj.getParent().getPosition());
        	parentRotation.addSelf(obj.getParent().getRotation());
        	obj=obj.getParent();
        }

        LogUtils.log("parent-rot:"+ThreeLog.get(GWTThreeUtils.radiantToDegree(parentRotation)));
        */
        // Matrix4 mx=GWTThreeUtils.rotationToMatrix4(parentRotation);
        // mx.multiplyVector3(parentPos);

        /*
        log("m:"+ThreeLog.get(selectedDraggablekObject.getPosition()));
        log("m:"+ThreeLog.get(GWTThreeUtils.toPositionVec(selectedDraggablekObject.getMatrix())));
        log("mw:"+ThreeLog.get(GWTThreeUtils.toPositionVec(selectedDraggablekObject.getMatrixWorld())));
        */
        // must be same as selectedDraggablekObject
        return newPos;
      } catch (Exception e) {
        LogUtils.log("moveSelectionPosition:" + e.getMessage());
        return null;
      }
    } else {
      return null;
    }
  }
예제 #3
0
  public void synchUI() {

    if (!initialized) { // do late
      initialize();
      initialized = true;
    }
    LogUtils.log(
        "sync:pos:"
            + PoseEditor.poseEditor.getRootPositionXRange()
            + ","
            + PoseEditor.poseEditor.getRootPositionYRange()
            + ","
            + PoseEditor.poseEditor.getCameraZ());

    // gif-panel
    backgroundCheck.setValue(isGifShowBackground());
    boneCheck.setValue(isGifShowBone());
    ikCheck.setValue(isGifShowIk());

    int screenshottype = getScreenshotBackgroundType();
    if (screenshottype == 0) {
      screenshotTransparentBt.setValue(true);
    } else if (screenshottype == 1) {
      screenshotColorBt.setValue(true);
      String scvalue = getScreenshotBackgroundValue();
      screenshotColorBox.setValue(scvalue);
    }

    lastBgImage = bgImage; // store for cancel
    lastBgLabel = bgImageLabel.getText();

    int bgType = storageControler.getValue(KEY_GIF_BG_TYPE, 1); // sadlly transparent not support
    String bgValue = storageControler.getValue(KEY_GIF_BG_VALUE, "#000000");

    LogUtils.log(bgType + "," + bgValue);

    if (bgType == 0) {
      transparentBt.setValue(true);
    } else if (bgType == 1) {
      colorBt.setValue(true);
      colorBox.setValue(bgValue);
    } else if (bgType == 2) {
      imageBt.setValue(true);
    }

    widthBox.setValue(Math.max(1, getGifWidth()));
    heightBox.setValue(Math.max(1, getGifHeight()));

    qualityBox.setValue(getGifQuality());
    speedBox.setValue(getGifSpeed());

    // keep value before set,if change value listener change others.
    int x = PoseEditor.poseEditor.getRootPositionXRange();
    int y = PoseEditor.poseEditor.getRootPositionYRange();
    int z = (int) (PoseEditor.poseEditor.getCameraZ() * 10);

    settingPositionXRange.setValue(x);
    settingPositionYRange.setValue(y);
    settingPositionZRange.setValue(z);

    lastRangeX = x;
    lastRangeY = y;
    lastRangeZ = z;

    updateCanvasSize();

    updatePreviewCanvas();
  }