Package cc.sketchchair.sketch

Examples of cc.sketchchair.sketch.SketchSpline


  public void addNewSketchShape() {

    for (int i = 0; i < this.getList().size(); i++) {
      SlicePlane curSlice = this.getList().get(i);
      SketchSpline newSketch = new SketchSpline(curSlice.getSketch());
      curSlice.getSketch().add(newSketch);
      curSlice.getSketch().setCurrentShape(newSketch);
    }
  }
View Full Code Here


    SketchShape selected = this.selectedPlanes.getSelectedShape();
    SlicePlane selectedPlane = this.selectedPlanes.getSelectedShapePlane();

    if (selected != null && selectedPlane != null) {
      if (selected instanceof SketchSpline) {
        SketchSpline SketchSpline = (SketchSpline) selected;
        selected = SketchSpline.getPath();
      }

      CrossSliceSelection selection = new CrossSliceSelection(selected,
          selectedPlane, .1f, .5f, 25f, this);
      selection.editing = true;
View Full Code Here

      this.initailSliceAdded = true;

      if (spline != null && spline instanceof SketchSpline) {
       

        SketchSpline sketchSpline = (SketchSpline) spline;
        CrossSliceSelection sliceSelection = new CrossSliceSelection(
            sketchSpline.getCentrePath(), extrudeSlice, 0, 1,
            SETTINGS.DEFAULT_SLAT_SPACING, this);
        sliceSelection.cropToCurrentShape = true;
        this.crossSliceSelections.add(sliceSelection);
       
       
       
      }

      if (spline instanceof SketchSpline) {

      }

      if (spline != null && spline instanceof SketchPath) {
        SketchPath path = (SketchPath) spline;
        path.setClosed(true);
        this.crossSliceSelections.add(new CrossSliceSelection(path,
            extrudeSlice, this.endCoverPercent,
            this.startCoverPercent, SETTINGS.DEFAULT_SLAT_SPACING,
            this));
        GLOBAL.uiTools.setCurrentTool(UITools.CROSSSLICE_EDIT);
      }
    } else {
      if (GLOBAL.uiTools.SketchTools.getCurrentTool() == SketchTools.LEG_TOOL
          && SETTINGS.addLegSlices) {

        SlicePlane extrudeSlice = this.selectedPlanes.getFirst();
        Object spline = extrudeSlice.getSketch().getLast();
        //CrossSliceSelection lastSliceSelection = this.crossSliceSelections.getLast();

        //build a list of all leg splines
        List legSplines = new ArrayList();
       
        for(int i = 0; i < this.selectedPlanes.size(); i++){
         
          this.selectedPlanes.get(i).getSketch().getLast().setType(SketchSpline.TYPE_LEG);
          legSplines.add(this.selectedPlanes.get(i).getSketch().getLast());
        }
        //SketchShape shape = lastSliceSelection.path;

        //if (!shape.equals(spline)) {
        if (spline instanceof SketchSpline) {
          SketchSpline sketchSpline = (SketchSpline) spline;

          if (sketchSpline.getCentrePath().size() == 2
              && sketchSpline
                  .getCentrePath()
                  .get(0)
                  .distanceTo(
                      sketchSpline.getCentrePath().get(1)) > SETTINGS.MIN_LEG_LEN) {
           
           
            CrossSliceSelection sliceSelection = new CrossSliceSelection(
                sketchSpline.getCentrePath(), extrudeSlice,
                this);
            extrudeSlice.tiedToLeg = true;
            sliceSelection.tieToLeg = true;
            sliceSelection.legSpline = sketchSpline;
            sliceSelection.legSplines = legSplines;
View Full Code Here

    if (constrain) {
      Object object = cropToSketch;

      if (object instanceof SketchSpline) {
        SketchSpline spline = (SketchSpline) object;
        ShetchShapesIntersect.add(spline.getPath());
      }

      if (object instanceof SketchPath) {
       
        //TODO: we need to make the crop to shop the correct one on each plane.
View Full Code Here

         * </pre>
         **/
        // we want to produce cross sections just across the current
        // sketch
        if (spline != null && spline instanceof SketchSpline) {
          SketchSpline currentSpline = (SketchSpline) spline;

          //LOGGER.info("slices on SketchSpline");

          if (currentSpline == null) {
            crossSliceSelection.destroy(null);
            return;
          }

          currentSpline = currentSpline;

          Vec2D topIntersect = null;
          Vec2D bottomIntersect = null;

          Vec2D intersectX = new Vec2D(-1, -1);

          Vec2D vecPosOnSpline = currentSpline.getPos(i);
         
          if(vecPosOnSpline != null){
          vecPos = new Vec3D(vecPosOnSpline.x,
              vecPosOnSpline.y,
              currentPlaneY.getPlane().z);

          Vec2D posPerp = currentSpline.getPerpendicular(i);
          float percent = -1f;
          Vec2D percentVec = new Vec2D(-1, -1);

          posPerp = posPerp.rotate(crossSliceSelection.offsetRotation);

          currentPlaneY.getIntersectionCentre(slicePlane,
              currentSpline, i, percentVec, intersectX);
         
         

          if(intersectX.x != -1 && intersectX.y!=-1){
         
         
          float splineWidth = currentSpline.getOffsetSize();
          splineWidth = currentSpline.getOffsetSize(i);

          //  float splineIntersectPercent = percentVec.x;
          //  if (splineIntersectPercent != -1) {

          Vec2D topIntersectY = null;
          Vec2D bottomIntersectY = null;

          float dist = 0;
          float neartestDist = -1;

          Vec2D tempPos = percentVec.copy();// currentSpline.getPos(percentVec.x);
          Vec2D tempDir = posPerp.copy();// currentSpline.getPerpendicular(percentVec.x);

          if (tempDir == null)
            break;

          tempDir = tempDir.normalize();

          topIntersect = intersectX.add(new Vec2D(0, splineWidth));
          bottomIntersect = intersectX.add(new Vec2D(0, -splineWidth));

          // Switch what side slots are added to
          // slots along Y
          Vec2D slotPos = new Vec2D(tempPos.x, tempPos.y);
          Vec2D slotDir = null;
          if (!crossSliceSelection.flipSide) {
            slotDir = new Vec2D(vecDir.x, vecDir.y);
          } else {
            slotDir = new Vec2D(-vecDir.x, -vecDir.y);
          }
          // slotPos.addSelf(slotDir.scale(100));
          float offsetToEdge = -1;
          if (!crossSliceSelection.flipSide) {
            offsetToEdge = 1;
          } else {
            offsetToEdge = -1;
          }

          if (!currentPlaneY.guide) {
            SliceSlot slot = new SliceSlot(slicePlane, slotPos,
                slotDir, (-splineWidth - offsetToEdge),
                SETTINGS.materialThickness);
            slot.swap();
            slot.setOnEdge(new Vec2D(0, 1));
           
if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
  slot.makesEdge = true;

            currentPlaneY.getSketch().getSlots().add(slot);
          }

          if (!currentPlaneY.guide) {
            if (!crossSliceSelection.flipSide) {
              if (j != 0 && j != planesToSlice.size() - 1 ){
                float yPosSlot = intersectX.y + (splineWidth);
                SliceSlot slot = new SliceSlot(
                    currentPlaneY,
                    new Vec2D(intersectX.x,yPosSlot),
                    new Vec2D(-1, 0), splineWidth,
                    SETTINGS.materialThickness);
                if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                  slot.makesEdge = true;
                        slot.setOnEdge(new Vec2D(0,-1)); // these slots start from the middle so this doesn't work, flip slots.

                       
                    //LOGGER.info("X " + slot.getPos().x + " Y " + slot.getPos().y );

                   
                slicePlane
                    .getSketch()
                    .getSlots()
                    .add(slot);
              }
            } else {
              if (j != 0 && j != planesToSlice.size() - 1){

                SliceSlot slot = new SliceSlot(
                    currentPlaneY,
                    new Vec2D(intersectX.x,
                        intersectX.y
                            - (splineWidth)),
                    new Vec2D(1, 0), splineWidth,
                    SETTINGS.materialThickness);
                slot.setOnEdge(new Vec2D(0, -1));
                if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                  slot.makesEdge = true;
                slicePlane
                    .getSketch()
                    .getSlots()
                    .add(slot);
               
              }
            }
          }

          // if(topIntersect != null){

          Vec3D tempVec = new Vec3D(bottomIntersect.x,
              bottomIntersect.y, 0);
          tempVec = slicePlane.getWorldPosIntersect(tempVec);

          if (SETTINGS.DEBUG) {
            currentPlaneY.debugIntersectionPoints.add(slotPos);
            currentPlaneY.debugIntersectionPointsTop.add(tempPos
                .scale(tempDir));
            currentPlaneY.debugIntersectionPointsBottom.add(tempPos
                .scale(tempDir.scale(-1)));
          }


          topLine.add(new SketchPoint(bottomIntersect));
          bottomLine.add(new SketchPoint(topIntersect));
          }
        }
        }

        //}

        /* ACROSS SKETCHPATH */

        /**
         * Find intersections across cross section
         *  
         *   <pre>
         *   currentPath
         *     ^
         *     |
         *    ------   x1 -> (topIntersect)
         *   |       \/ -------------------------> (crossSliceSelection)
         *   |       /\
         *   |      / /
         *    \    /  \
         *      \_/____\
         *       /
         *      x2 -> (bottomIntersect)
         *   </pre>
         */

        else if (spline instanceof SketchPath) {

          SketchPath currentPath = (SketchPath) spline;
         
          vecPos = new Vec3D(vecPos.x, vecPos.y,currentPlaneY.getPlane().z);
         
          //always crop to shape as we work out the correct shape earlier
          List<List<Vec2D>> points = currentPlaneY.getIntersection(
              slicePlane, true,
              currentPath);

          if (points != null && points.size() > 1) {

            Vec2D topIntersect = null;
            Vec2D bottomIntersect = null;
            Vec2D topIntersectY = null;
            Vec2D bottomIntersectY = null;
            Vec2D topIntersectX = null;
            Vec2D bottomIntersectX = null;
            float dist = 0;
            float neartestDist = -1;
            Vec2D vecStart = new Vec2D(vecPos.x, vecPos.y);

            //find the closest point
            for (int k = 0; k < points.size(); k++) {
             
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dX = (Vec2D) points.get(k).get(1);
              Vec3D vec3d = new Vec3D(vec2dX.x, vec2dX.y,vecPos.z);
              float d = vecStart.distanceTo(vec2dX);

              //Display intersects in debug mode
              if (SETTINGS.DEBUG) {
                currentPlaneY.debugIntersectionPoints
                    .add(vec2dX);
                currentPlaneY.debugIntersetStart = new Vec2D(
                    vecPos.x, vecPos.y);
              }

              if (d < neartestDist || neartestDist == -1) {
                neartestDist = d;
                topIntersect = vec2d;
                topIntersectX = vec2dX;
              }

            }

            float MIN_DUPLICATE_DIST = 2;

            //Remove the closest point
            for (int k = 0; k < points.size(); k++) {
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dx = (Vec2D) points.get(k).get(1);

              float distToLastIntersect = topIntersectX
                  .distanceTo(vec2dx);

              if (vec2d.equals(topIntersect)
                  || distToLastIntersect < MIN_DUPLICATE_DIST) {
                points.remove(k);
                k--;
              }

            }

            //find the next closest intersect!
            neartestDist = -1;
            for (int k = 0; k < points.size(); k++) {
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dX = (Vec2D) points.get(k).get(1);

              Vec3D vec3d = new Vec3D(vec2d.x, vec2d.y,
                  currentPlaneY.getPlane().z);
              float d = vecStart.distanceTo(vec2dX);

              if ((d < neartestDist && vec2d != topIntersect)
                  || neartestDist == -1) {

                neartestDist = d;
                bottomIntersect = vec2d;
                bottomIntersectX = vec2dX;
              }
            }

           
            /**
             * Lets Fix any intersects that are swapped around
             */
            if ((bottomIntersect != null && topIntersect != null)
                && bottomIntersect.y < topIntersect.y) {
              Vec2D topIntersectTemp = topIntersect.copy();
              Vec2D topIntersectXTemp = topIntersectX.copy();

              topIntersect = bottomIntersect;
              topIntersectX = bottomIntersectX;

              bottomIntersect = topIntersectTemp;
              bottomIntersectX = topIntersectXTemp;

            }

           
            /**
             * Are slats a set height?
             */
            if (crossSliceSelection.getSlatHeight() != 0) {
              bottomIntersect = topIntersect.add(0,
                  crossSliceSelection.getSlatHeight());
              bottomIntersectX = topIntersectX.add(0,
                  crossSliceSelection.getSlatHeight());
            }

            if (SETTINGS.DEBUG) {
              currentPlaneY.debugIntersectionPointsTop
                  .add(topIntersectX);
              currentPlaneY.debugIntersectionPointsBottom
                  .add(bottomIntersectX);

            }

            //if we have found both intersects then add them to the outline
            if (bottomIntersect != null && topIntersect != null) {
              float len = bottomIntersect
                  .distanceTo(topIntersect);

              if (!currentPlaneY.guide) {

                if (crossSliceSelection.flipSide) {
                  Vec2D slotPos = bottomIntersectX.copy();
                  Vec2D dirPerp = new Vec2D(vecDir.x,
                      vecDir.y);
                  dirPerp.rotate((float) (Math.PI / 2));
                  SliceSlot slot = new SliceSlot(slicePlane,
                      slotPos, new Vec2D(
                          -vecDir.x,
                          -vecDir.y),
                      (len / 2f),
                      SETTINGS.materialThickness);
                  slot.setOnEdge(new Vec2D(0, -1));
                  if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                    slot.makesEdge = true;
                  currentPlaneY
                      .getSketch()
                      .getSlots()
                      .add(slot);

                } else {
                  Vec2D slotPos = topIntersectX.copy();
                  Vec2D dirPerp = new Vec2D(vecDir.x,
                      vecDir.y);
                  dirPerp.rotate((float) (Math.PI / 2));
                  SliceSlot slot = new SliceSlot(slicePlane,
                      slotPos,
                      new Vec2D(vecDir.x,
                          vecDir.y),
                      (len / 2f),
                      SETTINGS.materialThickness);
                  slot.setOnEdge(new Vec2D(0, -1));
                  if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                    slot.makesEdge = true;
                  // Switch what side slots are added to
                  currentPlaneY
                      .getSketch()
                      .getSlots()
                      .add(slot);
                }
              }

              Vec2D topSlotintersect = bottomIntersect.copy();
              Vec2D bottomtopSlotintersect = topIntersect.copy();

              if (!currentPlaneY.guide) {

                if (!crossSliceSelection.flipSide) {
                  if (j != 0
                      && j != planesToSlice.getList()
                          .size() - 1){
                    SliceSlot slot = new SliceSlot(
                        currentPlaneY,
                        topSlotintersect,
                        new Vec2D(-1, 0),
                        (len / 2f),
                        SETTINGS.materialThickness);
                    slot.setOnEdge(new Vec2D(0, -1));
                    if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                      slot.makesEdge = true;
                    slicePlane
                        .getSketch()
                        .getSlots()
                        .add(slot);
                  }
                } else {
                  if (j != 0
                      && j != planesToSlice.getList()
                          .size() - 1){
                    SliceSlot slot = new SliceSlot(
                        currentPlaneY,
                        bottomtopSlotintersect,
                        new Vec2D(1, 0),
                        ((len / 2f)),
                        SETTINGS.materialThickness);
                    slot.setOnEdge(new Vec2D(0, -1));
                    if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                      slot.makesEdge = true;
                    slicePlane
                        .getSketch()
                        .getSlots()
                        .add(slot);
                  }
                }
              }
              // if(topIntersect != null){

              // add bezier points

              /**
               * BUILD the legs
               *
               * ________
               * |:/  \:|
               * ||    ||
               * --    --
               */
             
              if (crossSliceSelection.tieToLeg) {
                // if(crossSliceSelection.tiedToPlanes.contains(currentPlaneY)){
               
               
                if (crossSliceSelection.legSpline != null
                    && crossSliceSelection.legSpline
                        .getPath() != null
                    && crossSliceSelection.tiedToPlanes.contains(currentPlaneY)) {
                 
                 
                 
                 
                 
                  Vec2D seatBottom = null;

                  if(crossSliceSelection.extendLegSliceToTopOfLeg){
                    seatBottom = new Vec2D(0,0);
                  }else{
                 
                   
                    SketchShapes tempSketchShapes = currentPlaneY.getSketch().getSketchShapes().clone();
                   
                    tempSketchShapes.removeLegs();
                    tempSketchShapes.sketchOutlines.clear();
                    tempSketchShapes.buildOutline();
                   
                    if (tempSketchShapes.sketchOutlines
                        .getOutterOutline() == null)
                      return;
                   
                   
                    SketchShape sktch = tempSketchShapes.sketchOutlines.getOutterOutline().getPath();

                   
                    List<List<Vec2D>> points02 = currentPlaneY.getIntersection(
                        slicePlane, true,
                        sktch);
                   
                   
                    for (int k = 0; k < points02.size(); k++) {
                     
                      Vec2D vec2d = (Vec2D) points02.get(k).get(0);
                      if(seatBottom == null || vec2d.distanceTo(topIntersect) > vec2d.distanceTo(seatBottom) )
                        seatBottom = vec2d;
                     
                    }
           
                 
                   if(seatBottom == null)
                    seatBottom = bottomIntersect;
                 
                  }
                  // this is hard coded so legs are always on
                  // the outside slices!
                  topLine.add(new SketchPoint(topIntersect));


                  //bottomLine.add(new SketchPoint(bottomIntersect));
                  float legWidthBottom = 20;
                  float legWidthTop = 20;
                  SketchSpline legSpline = crossSliceSelection.legSpline;
                  float Yoffset = 0;
                  float yMin = 0;
                 
                  SketchPoint p1 = null, p2, p3, p4;
                  if (legSpline.getPath().size() == 4) {
                    p1 = (SketchPoint) legSpline.getPath()
                        .get(1);
                    p2 = (SketchPoint) legSpline.getPath()
                        .get(2);

                    p3 = (SketchPoint) legSpline.getPath()
                        .get(0);
                    p4 = (SketchPoint) legSpline.getPath()
                        .get(3);

                    legWidthBottom = p1.distanceTo(p2);
                    legWidthTop = p3.distanceTo(p4);
                    Yoffset = 0;
                   
                   
                   
                    Vec2D p5 = GLOBAL.uiTools.getPointOnPlane(legSpline.getCentrePath().get(0), slicePlane.getPlane());
                    Vec2D p6 = GLOBAL.uiTools.getPointOnPlane(legSpline.getCentrePath().get(1), slicePlane.getPlane());

                    //slicePlane.getPlane().getIntersectionWithRay(r);
                    yMin = 29;//Math.min(p5.y,p6.y);
                   

View Full Code Here

TOP

Related Classes of cc.sketchchair.sketch.SketchSpline

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.