We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys,
I'm pretty inexperienced when it comes to python and it's probably the reason why I'm having trouble but, the Issue i'm having is placing a 3D renderer (proscene) into a 2D "Canvas". The idea is to have the 3D window running along side a 2D sketch. Here's the code from my main.py:
add_library('proscene')
from PlaneConstructor import ThreeDimensionalPlane
from PrismConstructor import RectangularPrism
from ReadFile import readFile
def setUpScene():
scene.setGridVisualHint(False)
scene.setAxesVisualHint(False)
if scene.is3D():
scene.setCameraType(Camera.Type.ORTHOGRAPHIC)
scene.setRadius(150)
scene.showAll()
def setup():
global scene, offset
size(1200,1200,P3D)
scene = Scene(this)
listOfPlanes = readFile(fileName)
createSections(listOfPlanes)
setUpScene()
beamLength = calcBeamLength(listOfPlanes)
offset = -1 * (float(beamLength) / 2)
def draw():
background(140)
drawSections(offset)
From what I've already read online, setup is where all the magic happens and I've tried implementing the solution from 3D window in 2D sketch, however when running the code with the changes, the 3D image stays as 2D and I can't draw anything outside the 3D window.
What are some other ways of implementing this?
Answers
That @codeanticode's example is too old, from November of 2013:
https://forum.Processing.org/two/discussion/1297/3d-window-in-2d-sketch#Item_7
So before going to Python Mode, let's 1st scrub the original Java Mode sketch: #:-S
And w/o further ado, here's what I've come up w/ for the Python Mode version: :-bd
As a bonus, a variant w/ multicolor boxes using a Cube class: B-)
I understand how your code works, Thanks! however now I'm getting my proScene window as a 2D image. I feel like I'm not putting something crucial in draw, however it could also mean that I'm drawing the window on top of the scene. Here are the changes that I've made:
Does that mean it's run successfully for ya too? :-/
Unfortunately I can't run your own version b/c you
import
libraries I dunno about! :|Only 1 I've heard about was proscene. Yet this was the 1st time I've ever used it! 8-|
And my huge ignorance about the Python language and its ecosystem doesn't help either! X_X
My advice is that you'd favor "javaism" over "pythonic" ways.
That is, before relying on some exclusive Python feature, take a look 1st whether Processing's API or Java's API already offer that:
Some possible examples:
You're using readFile in order to load some "'csv" file: "file1.csv".
Yet Processing got loadTable(): https://Processing.org/reference/loadTable_.html
Some cross Java/Python Mode examples:
listOfPlanes = loadTable("file1.csv")
csv = loadTable("http://" + "WebRates.TrueFX.com/" + "rates/connect.html" + "?f=csv", "csv")
Dunno what is a ThreeDimensionalPlane. Perhaps it's kinda PVector: :-??
http://py.Processing.org/reference/PVector.html
No idea about RectangularPrism either. Maybe some Java's Rectangle:
http://docs.Oracle.com/javase/8/docs/api/java/awt/Rectangle.html
Following this path's gonna enable more of us to help ya out.
Given that most of us are more knowledgeable about Java Mode. ~O)
I'm mainly a java programmer too and this project is lead by someone who persists on using python... I think I'll try writing it in java and going from there :-??
Thanks for the help though! You've shown be that I've got a bit more work to do B-)
@thepizzagui, as I've shown, 1st have a working Java Mode version.
Then you can decide to re-write it in Python Mode in order to please your leader. ;))
More forum threads where the original Java Mode was converted to Python Mode too: :ar!
Did you check this example where a 2D canvas is created on top of a 3D one?