/** * this demo shows how to grab a sketch into a texture and then render it onto a wavefront 3D model. * the interesting part is that the 3D model can be modelled in a 3D application. a placeholder * for the sketch is then placed onto the model to generate the right UV coordinates. finally the * model is exported as a 'wavefront' .obj file. */ import gestalt.Gestalt; import gestalt.candidates.JoglFrameBufferCopy; import gestalt.model.Model; import gestalt.model.ModelData; import gestalt.model.ModelLoaderOBJ; import gestalt.p5.GestaltPlugIn; import gestalt.shape.Mesh; import gestalt.shape.material.TexturePlugin; import gestalt.texture.bitmap.IntegerBitmap; import gestalt.util.CameraMover; import processing.opengl.*; /** @todo * there are still some issues. for example lighting doesn t properly work yet. */ GestaltPlugIn gestalt; Model _myModel; void setup() { /* setup p5 */ size(1024, 512, OPENGL); ellipseMode(CENTER); smooth(); gestalt = new GestaltPlugIn(this); /* * keep gestalt from clearing any buffers. * we do this after we copied the framebuffer into a texture */ gestalt.framesetup().depthbufferclearing = false; gestalt.framesetup().colorbufferclearing = false; /* create an empty dummy bitmap */ TexturePlugin myTexture = gestalt.drawablefactory().texture(); myTexture.load(IntegerBitmap.getDefaultImageBitmap(width, height)); /* create the model */ /* model */ ModelData myModelData = ModelLoaderOBJ.getModelData(openStream("weirdobject.obj")); Mesh myModelMesh = gestalt.drawablefactory().mesh(true, myModelData.vertices, 3, myModelData.vertexColors, 4, myModelData.texCoordinates, 2, myModelData.normals, myModelData.primitive); _myModel = gestalt.drawablefactory().model(myModelData, myModelMesh); _myModel.getView().material().addPlugin(myTexture); myTexture.setWrapMode(Gestalt.TEXTURE_WRAPMODE_CLAMP); myTexture.rescale().y = 1; _myModel.getView().material().lit = true; _myModel.getView().material().transparent = false; gestalt.bin(Gestalt.BIN_3D).add(_myModel); /* camera */ gestalt.camera().setMode(Gestalt.CAMERA_MODE_LOOK_AT); gestalt.camera().position().set(150, 100, 450); /* light */ gestalt.light().enable = true; gestalt.light().position = gestalt.camera().position(); /* create a screengrabber */ JoglFrameBufferCopy myFrameBufferCopy = new JoglFrameBufferCopy(myTexture); myFrameBufferCopy.backgroundcolor.set(0.2f, 1); myFrameBufferCopy.width = width; myFrameBufferCopy.height = height; gestalt.bin(Gestalt.BIN_3D_SETUP).add(myFrameBufferCopy); } void draw() { /* clear screen */ background(0, 255, 127); /* draw processing stuff */ fill(255, 255); stroke(0, 255); strokeWeight(20); ellipse(mouseX, mouseY, 200, 200); /* move camera */ final float myDeltaTime = 1 / 30f; CameraMover.handleKeyEvent(gestalt.camera(), gestalt.event(), myDeltaTime); gestalt.camera().side(myDeltaTime * 20); /* change wrap mode */ if (gestalt.event().mouseDown) { if (gestalt.event().mouseButton == Gestalt.MOUSEBUTTON_LEFT) { gestalt.enable(); } else { gestalt.disable(); } } }