# Shapes3D: Box.draw() doesn't work anymore (new version of library)

**URL:** <https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860>\
**Category:** Libraries\
**Created:** [November 24, 2022, 4:51pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860 "2022-11-24T16:51:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 24, 2022, 4:51pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/1 "2022-11-24T16:51:26Z")

</div>

@quark

using shapes3d (from a very old Sketch from my archives) here and wanted to say (used to say) ` MyBoxes[i].draw();`

- 
  - doesn’t work anymore

It seems, it used to work without a parameter, but now it doesn’t?

Thanks!

Chrisir

MCVE :

```auto

// imports ================================================

import shapes3d.utils.*;
import shapes3d.*;

Box [] MyBoxes = new Box [33]; // array

void setup () {

  size (800, 600, P3D);

  // Init
  for (int i = 0; i < 33; i = i+1) {
    MyBoxes[i] = new Box( 44, 3, 44 ); 
    MyBoxes[i].visible(true); // was "false" 
  } // for
}

void draw () {
  background(0);
  PaintIt ();
}

void PaintIt () {
  for (int i = 0; i < 33; i++) {
    fill(255); 
    MyBoxes[i].draw();
  }//for
} // function 

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [November 24, 2022, 5:07pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/2 "2022-11-24T17:07:18Z")

</div>

Several things here.

1. The latest version of Shapes3D (v3.0) was a complete rewrite of the library and is not backwardly compatible
2. In your code all the boxes are set invisible 😄
3. The draw method now expects a parameter of type PGraphics so to draw the shape to the main display use `MyBoxes[i].draw(getGraphics());`

The reason for the (3) is that it allows shapes to be drawn to offscreen buffers and to improve integration with later versions of G4P

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 24, 2022, 5:18pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/3 "2022-11-24T17:18:36Z")

</div>

This works!

Thank you so much!

```auto
// imports 
import shapes3d.*;

Box [] myBoxes = new Box [33]; // array

void setup () {
  size (800, 600, P3D);

  // Init
  for (int i = 0; i < 33; i++) {
    myBoxes[i] = new Box( 44, 3, 44 ); 
    myBoxes[i].moveTo(i*10+width/2, 100 + i*14, -3*i); 
    myBoxes[i].visible(true); // was "false"
  } // for
} // function

void draw () {
  background(0);
  paintIt ();
} // function

void paintIt () {
  for (int i = 0; i < 33; i++) {
    // myBoxes[i].fill(255); 
    myBoxes[i].draw(getGraphics()); // !!!!!
  }//for
} // function
//

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 5, 2023, 2:41pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/4 "2023-10-05T14:41:07Z")

</div>

@quark: excuse me, and how can I replace the `pickShape()` method?

```auto
    Shape3D picked = null;
    picked = Shape3D.pickShape(this, mouseX, mouseY);
    if (picked != null) {
      done = true;
      MakeHumanMove(picked.tagNo);
    }

```

and could you please add `Toroid` back into the library? 😉

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 5, 2023, 4:34pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/5 "2023-10-05T16:34:58Z")

</div>

> [@Chrisir](#):
>
> and could you please add `Toroid` back into the library? 😉

I have answered this in your other discussion 😀

> [@Chrisir](#):
>
> excuse me, and how can I replace the `pickShape()` method?

Think you need to expand on this question - why replace it? what to replace it with?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 5, 2023, 6:22pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/6 "2023-10-05T18:22:58Z")

</div>

> [@quark](#):
>
> why replace it? what to replace it with?

sorry, this is more a “this used to work and now it doesn’t”-question

— I was using the code (shown above) in a not so old Sketch and now it doesn’t work anymore.

_Have the numbers of parameters changed or their types?_

Thanks a ton!

Chrisir

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 5, 2023, 7:41pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/7 "2023-10-05T19:41:11Z")

</div>

> [@Chrisir](#):
>
> Have the numbers of parameters changed or their types?

Yes there is an extra parameter. Prior to V3 the pick function assumed that all shapes were drawn to the main sketch window. In V3 this changed so that shapes could be drawn to different _viewports_ (PGraphics instances).  
So your method  
`picked = Shape3D.pickShape(this, mouseX, mouseY);`  
becomes  
`picked = Shape3D.pickShape(this, getGraphics(), mouseX, mouseY);`

I strongly recommend you look at the examples that come with V3 and also look at the [guides](http://www.lagers.org.uk/s3d4p/libguides/lg01-introduction.html) for V3.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 5, 2023, 8:03pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/8 "2023-10-05T20:03:58Z")

</div>

> [@quark](#):
>
> picked = Shape3D.pickShape(this, getGraphics(), mouseX, mouseY);

You could easily overload that method to just 3 parameters as it was before; given **getGraphics()** can be invoked by using the 1st parameter, which is of PApplet datatype: 🧙

```auto
public static Shape3D pickShape(PApplet papplet, int x, int y) {
    return pickShape(papplet, papplet.getGraphics(), x, y);
}

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 6, 2023, 8:08am UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/9 "2023-10-06T08:08:29Z")

</div>

> [@GoToLoop](#):
>
> You could easily overload that method to just 3 parameters as it was before

Good idea, wish I had thought of it first 😄

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 6, 2023, 11:03am UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/10 "2023-10-06T11:03:50Z")

</div>

> [@quark](#):
>
> `picked = Shape3D.pickShape(this, getGraphics(), mouseX, mouseY);`

this doesn’t work…

in the reference [Shapes 3D: Main Page](http://www.lagers.org.uk/s3d4p/ref/index.html) there ain’t  
pickShape

There is pick, but it returns Picked, which is not a Shape3D?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 6, 2023, 12:39pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/11 "2023-10-06T12:39:44Z")

</div>

My mistake should be

```auto
picked = Shape3D.pick(this, getGraphics(), mouseX, mouseY);
shape = picked.shape;

```

The class `Picked` is a public access class with 3 constants  
`shape` : reference to the shape picked  
`part` : id of the part of the shape picked (integer)  
`partID` : binary flag showing the part picked (integer)

Sorry about that but V3 was released in January 2020 and I can’t remember what was in previous versions because they have been _entirely_ replaced by V3.

V3 comes with new examples including those showing shape picking.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 6, 2023, 2:03pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/12 "2023-10-06T14:03:51Z")

</div>

thank you, this works

```auto

void mousePressedBoard () {
  // mouse evaluate.
  // Check what's been pressed by the mouse.

  // when we have a winner, we leave !!!
  if (winnerIs!=-1) {
    return; //leave
  }
  if (status != constStatusFeld_O) {
    return;
  }

  boolean done = false;

  // Wenn linke Taste UND camera not mouse controlled
  if ((mouseButton == LEFT) &&
    (camIsMouseControlled==false)) {
    // by Quark: http://www.lagers.org.uk/s3d4p/index.html

    Picked pickedTemp = Shape3D.pick(this, getGraphics(), mouseX, mouseY);

    if (pickedTemp!=null) {
      Shape3D picked = pickedTemp.shape;

      if (picked != null) {
        done = true;
        MakeHumanMove(picked.tagNo);
      }
    }
  }
} // mouseClicked
//

```

* * *

**Screenshot:**

 ![dd2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/9/2957f86fe1581ddf2bc45cf145e79cd847507bbb.png)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 6, 2023, 4:42pm UTC](https://discourse.processing.org/t/shapes3d-box-draw-doesnt-work-anymore-new-version-of-library/39860/13 "2023-10-06T16:42:44Z")

</div>

> [@quark](#):
>
> … V3 was released in January 2020 and I can’t remember what was in previous versions…

[“Shape3D.java” from 2017-01-09](https://sourceforge.net/p/shapes3d/code/ci/f9be8edf57c820ae10ad3557b16f8e2fe1b426aa/tree/Shapes%203D/src/shapes3d/Shape3D.java)

```java
	public static Shape3D pickShape(PApplet papplet, int x, int y){
		if(pickBuffer == null || pickBuffer.width != papplet.width || pickBuffer.height != papplet.height){
			pickBuffer = (PGraphics3D) papplet.createGraphics(papplet.width, papplet.height, P3D);
		}
		pickBuffer.noSmooth();
		pickBuffer.beginDraw();
		// Set the camera same as the drawing surface
		pickBuffer.camera.set(((PGraphicsOpenGL)papplet.g).camera);
		pickBuffer.projection.set(((PGraphicsOpenGL)papplet.g).projection);
		pickBuffer.modelview.set(((PGraphicsOpenGL)papplet.g).modelview);
		pickBuffer.noLights();
		pickBuffer.noStroke();
		pickBuffer.background(WHITE);

		// Draw to the buffer
		pickModeOn = true;
		drawAll();
		pickBuffer.endDraw();

		int c = pickBuffer.get(x,y);
		pickModeOn = false;

		// Next line inserted just to get a copy of the buffer for testing
		// make sure it is commented out before release.
		//img = pickBuffer.get(); 
		
		return pickMap.get(c);
	}

```
