Working in Eclipse (proclipsing) with mesh attarctors.
in
Contributed Library Questions
•
1 year ago
Hello,
I am working in Eclipse with processing script.
The script is about grid distortion.
According to distance to points I want to distort mesh.
By pressing 'a' or 'b' button you can move one of the
points.
Questions:
1. I cannot figure out where to write calculation:
between grid points and attractor points. Please tell me
where to put the calculation and why, ech I am just a new
user...
2. I have a script working with one point. But when I
want to make more than one attractor point/a group I don't know
the concept how to deal with it. I tried to add the location
of different attractor points, but result comes out as
new ONE point with addition of points loction...
Thank you in advance,
Petras Vestartas.
package toximeshat;
import processing.core.PApplet;
import peasy.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.ToxiclibsSupport;
import controlP5.*;
public class ToxiMeshAt extends PApplet {
PeasyCam cam;
Grid myGrid;
TriangleMesh mesh;
ToxiclibsSupport gfx;
float currentY;
float force;
Vec3D pt1 = new Vec3D (-20, 0, 0);
Vec3D pt2 = new Vec3D (120, 0, 0);
float d1;
float d2;
public void setup() {
size(600,600,P3D);
cam = new PeasyCam(this,100);
myGrid = new Grid(this, 11, 11, 10 , 10);
mesh = new TriangleMesh("meshy");
gfx = new ToxiclibsSupport (this);
}
public void draw() {
background(0);
stroke(255);
strokeWeight(10);
noFill();
point(mouseX-width/2, mouseY-height/2);
Vec3D m = new Vec3D (mouseX-width/2, mouseY-height/2, 0);
float d1 = m.distanceTo(pt1);
if ((keyPressed == true) && (key == 'a')) {
if (d1<10) {
pt1=m;
}
}
point(pt2.x, pt2.y, pt2.z);
float d2 = m.distanceTo(pt2);
if ((keyPressed == true) && (key == 'b')) {
if (d2<10) {
pt2=m;
}
}
stroke(255,0,0);
strokeWeight(20);
point(pt1.x, pt1.y, pt1.z);
stroke(0,0,255);
point(pt2.x, pt2.y, pt2.z);
mesh.clear();
stroke(255);
strokeWeight(1);
noFill();
rect(0,0,100,100);
fill(255,100);
myGrid.run();
gfx.mesh(mesh);
}
}
package toximeshat;
import toxi.geom.Vec3D;
public class Pt {
ToxiMeshAt p5;
Vec3D loc;
int idX;
int idY;
Grid parent;
float currentY;
float force;
Vec3D pt1 = new Vec3D (0, 0, 0);
float d1;
Pt(ToxiMeshAt _p5,Grid _parent, Vec3D _loc, int _idX, int _idY, float _currentY, float _force, Vec3D _pt1, float _d1){
p5 = _p5;
parent = _parent;
loc = _loc;
idX = _idX;
idY = _idY;
float currentY = _currentY;
float force = _force;
Vec3D pt1 = _pt1;
float d1 = _d1;
}
void run (){
display();
update();
drawConnections();
}
void update() {
//update y-coordinate, depending on distance to repellor
float distance = loc.distanceTo(pt1);
currentY = loc.y + (force)/(distance);
}
void drawConnections(){
if(idX < parent.cols-1 && idY < parent.rows-1){
//Vec3D me = parent.allPts[idX][idY].loc; = loc
Vec3D meRight = parent.allPts[idX+1][idY].loc.copy();
Vec3D meDown = parent.allPts[idX][idY+1].loc.copy();
Vec3D meDiag = parent.allPts[idX+1][idY+1].loc.copy();
p5.mesh.addFace(loc.copy(), meRight, meDiag);
p5.mesh.addFace(meDiag, meDown, loc.copy());
}
}
void display(){
p5.stroke(0,255,0);
p5.strokeWeight(1);
p5.point(loc.x, loc.y, loc.z);
}
}
package toximeshat;
import toxi.geom.Vec3D;
public class Grid {
ToxiMeshAt p5;
int cols;
int rows;
Pt [][] allPts;
float scaleX;
float scaleY;
Grid(ToxiMeshAt _p5, int _cols, int _rows, float _scaleX, float _scaleY){
p5 = _p5;
cols = _cols;
rows = _rows;
float scaleX = _scaleX;
float scaleY = _scaleY;
allPts = new Pt[cols][rows];
for(int i = 0; i < cols; i++){
for(int j = 0; j < rows; j++){
Vec3D v = new Vec3D (i * scaleX,j*scaleY,0);
allPts[i][j] = new Pt (p5, this, v, i, j, scaleY, scaleY, v, scaleY );
}
}
}
void run(){
runPoints();
}
void runPoints(){
for(int i = 0; i < cols; i++){
for(int j = 0; j < rows; j++)
allPts[i][j].run();
}
}
}
I am working in Eclipse with processing script.
The script is about grid distortion.
According to distance to points I want to distort mesh.
By pressing 'a' or 'b' button you can move one of the
points.
Questions:
1. I cannot figure out where to write calculation:
between grid points and attractor points. Please tell me
where to put the calculation and why, ech I am just a new
user...
2. I have a script working with one point. But when I
want to make more than one attractor point/a group I don't know
the concept how to deal with it. I tried to add the location
of different attractor points, but result comes out as
new ONE point with addition of points loction...
Thank you in advance,
Petras Vestartas.
package toximeshat;
import processing.core.PApplet;
import peasy.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.ToxiclibsSupport;
import controlP5.*;
public class ToxiMeshAt extends PApplet {
PeasyCam cam;
Grid myGrid;
TriangleMesh mesh;
ToxiclibsSupport gfx;
float currentY;
float force;
Vec3D pt1 = new Vec3D (-20, 0, 0);
Vec3D pt2 = new Vec3D (120, 0, 0);
float d1;
float d2;
public void setup() {
size(600,600,P3D);
cam = new PeasyCam(this,100);
myGrid = new Grid(this, 11, 11, 10 , 10);
mesh = new TriangleMesh("meshy");
gfx = new ToxiclibsSupport (this);
}
public void draw() {
background(0);
stroke(255);
strokeWeight(10);
noFill();
point(mouseX-width/2, mouseY-height/2);
Vec3D m = new Vec3D (mouseX-width/2, mouseY-height/2, 0);
float d1 = m.distanceTo(pt1);
if ((keyPressed == true) && (key == 'a')) {
if (d1<10) {
pt1=m;
}
}
point(pt2.x, pt2.y, pt2.z);
float d2 = m.distanceTo(pt2);
if ((keyPressed == true) && (key == 'b')) {
if (d2<10) {
pt2=m;
}
}
stroke(255,0,0);
strokeWeight(20);
point(pt1.x, pt1.y, pt1.z);
stroke(0,0,255);
point(pt2.x, pt2.y, pt2.z);
mesh.clear();
stroke(255);
strokeWeight(1);
noFill();
rect(0,0,100,100);
fill(255,100);
myGrid.run();
gfx.mesh(mesh);
}
}
package toximeshat;
import toxi.geom.Vec3D;
public class Pt {
ToxiMeshAt p5;
Vec3D loc;
int idX;
int idY;
Grid parent;
float currentY;
float force;
Vec3D pt1 = new Vec3D (0, 0, 0);
float d1;
Pt(ToxiMeshAt _p5,Grid _parent, Vec3D _loc, int _idX, int _idY, float _currentY, float _force, Vec3D _pt1, float _d1){
p5 = _p5;
parent = _parent;
loc = _loc;
idX = _idX;
idY = _idY;
float currentY = _currentY;
float force = _force;
Vec3D pt1 = _pt1;
float d1 = _d1;
}
void run (){
display();
update();
drawConnections();
}
void update() {
//update y-coordinate, depending on distance to repellor
float distance = loc.distanceTo(pt1);
currentY = loc.y + (force)/(distance);
}
void drawConnections(){
if(idX < parent.cols-1 && idY < parent.rows-1){
//Vec3D me = parent.allPts[idX][idY].loc; = loc
Vec3D meRight = parent.allPts[idX+1][idY].loc.copy();
Vec3D meDown = parent.allPts[idX][idY+1].loc.copy();
Vec3D meDiag = parent.allPts[idX+1][idY+1].loc.copy();
p5.mesh.addFace(loc.copy(), meRight, meDiag);
p5.mesh.addFace(meDiag, meDown, loc.copy());
}
}
void display(){
p5.stroke(0,255,0);
p5.strokeWeight(1);
p5.point(loc.x, loc.y, loc.z);
}
}
package toximeshat;
import toxi.geom.Vec3D;
public class Grid {
ToxiMeshAt p5;
int cols;
int rows;
Pt [][] allPts;
float scaleX;
float scaleY;
Grid(ToxiMeshAt _p5, int _cols, int _rows, float _scaleX, float _scaleY){
p5 = _p5;
cols = _cols;
rows = _rows;
float scaleX = _scaleX;
float scaleY = _scaleY;
allPts = new Pt[cols][rows];
for(int i = 0; i < cols; i++){
for(int j = 0; j < rows; j++){
Vec3D v = new Vec3D (i * scaleX,j*scaleY,0);
allPts[i][j] = new Pt (p5, this, v, i, j, scaleY, scaleY, v, scaleY );
}
}
}
void run(){
runPoints();
}
void runPoints(){
for(int i = 0; i < cols; i++){
for(int j = 0; j < rows; j++)
allPts[i][j].run();
}
}
}
1