//import java.util.Vector;
|
|
abstract class Biparam extends Object3D implements java.io.Serializable
|
{
|
static final long serialVersionUID = 6172913067490775416L;
|
|
abstract Vertex biparamFunction(double f, double f1);
|
|
Biparam()
|
{
|
name = "Biparam";
|
endcaps = false;
|
bRep = new BoundaryRep();
|
|
mode = 0;
|
CreateMaterial();
|
}
|
|
void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
|
{
|
//System.out.println("#vertices = " + bRep.VertexCount());
|
if(false)
|
for(int i=0; i<bRep.VertexCount(); i++)
|
{
|
Vertex v = bRep.GetVertex(i);
|
double x = v.x;
|
double y = v.y;
|
double z = v.z;
|
int G = 65536;
|
x = Math.floor(x*G)/G;
|
y = Math.floor(y*G)/G;
|
z = Math.floor(z*G)/G;
|
cStatic.random.setSeed(Double.doubleToLongBits(x) ^ Double.doubleToLongBits(y) ^ Double.doubleToLongBits(z));
|
v.x += (cStatic.random.nextFloat() - 0.5) * 0.1;
|
v.y += (cStatic.random.nextFloat() - 0.5) * 0.1;
|
v.z += (cStatic.random.nextFloat() - 0.5) * 0.1;
|
bRep.SetVertex(v, i);
|
}
|
|
if (reset)
|
{
|
this.recalculate();
|
reset = false;
|
}
|
|
super.DrawNode(display, root, selected);
|
}
|
|
protected void deepCopyNode(Object3D other)
|
{
|
super.deepCopyNode(other);
|
Biparam bp = (Biparam)other;
|
bp.uDivs = uDivs;
|
bp.vDivs = vDivs;
|
bp.endcaps = endcaps;
|
}
|
|
transient boolean touched = false;
|
|
void retile()
|
{
|
//System.out.println("BREP TRIMMED? 1 " + bRep.trimmed);
|
ClearList();
|
if (endcaps)
|
bRep.redimension((uDivs + 1) * (vDivs + 1) + (uDivs + 1) * 2 + 2, uDivs * (vDivs + 1) * 2);
|
else
|
bRep.redimension((uDivs + 1) * (vDivs + 1), uDivs * vDivs * 2);
|
int ix = 0;
|
for (int u = 0; u < uDivs; u++)
|
{
|
for (int v = 0; v < vDivs; v++)
|
{
|
int p = u * (vDivs + 1) + v;
|
int q = p + 1;
|
int r = p + vDivs + 1;
|
int s = r + 1;
|
if ((u+v)%2 == 1)
|
{
|
bRep.setFace(ix++, p, s, q);
|
bRep.setFace(ix++, p, r, s);
|
}
|
else
|
{
|
bRep.setFace(ix++, p, r, q);
|
bRep.setFace(ix++, r, s, q);
|
}
|
}
|
|
if (endcaps)
|
{
|
int p = (uDivs + 1) * (vDivs + 1) + u;
|
int q = p + 1;
|
int r = (uDivs + 1) * (vDivs + 1) + (uDivs + 1) * 2;
|
bRep.setFace(ix++, p, r, q);
|
p += uDivs + 1;
|
q = p + 1;
|
r++;
|
bRep.setFace(ix++, p, q, r);
|
}
|
}
|
//System.out.println("BREP TRIMMED? 2 " + bRep.trimmed);
|
|
touched = true;
|
// recalculate();
|
}
|
|
double uStretch()
|
{
|
return 1;
|
}
|
|
double vFlip(double v)
|
{
|
return v;
|
}
|
|
void recalculate()
|
{
|
//System.out.println("BREP TRIMMED? 3 " + bRep.trimmed);
|
double du = (double)uDivs;
|
double dv = (double)vDivs;
|
double u = 0;
|
for (int iu = 0; iu < uDivs + 1; iu++)
|
{
|
u = iu/du;
|
double v = 0;
|
for (int iv = 0; iv < vDivs + 1; iv++)
|
{
|
v = iv/dv;
|
Vertex vert = biparamFunction(u, v);
|
int p = iu * (vDivs + 1) + iv;
|
if (touched)
|
{
|
vert.s = u * uStretch();
|
vert.t = vFlip(v);
|
}
|
else
|
{
|
Vertex old = bRep.GetVertex(p);
|
vert.s = old.s;
|
vert.t = old.t;
|
}
|
//bRep.vertices.setElementAt(vert, p);
|
bRep.SetVertex(vert, p);
|
v += dv;
|
}
|
|
if (endcaps)
|
{
|
int p = iu * (vDivs + 1);
|
int q = (uDivs + 1) * (vDivs + 1) + iu;
|
//Vertex vert = (Vertex)bRep.vertices.elementAt(p);
|
Vertex vert = bRep.GetVertex(p);
|
//bRep.vertices.setElementAt(vert, q);
|
bRep.SetVertex(vert, q);
|
p += vDivs;
|
q += uDivs + 1;
|
//vert = (Vertex)bRep.vertices.elementAt(p);
|
//bRep.vertices.setElementAt(vert, q);
|
vert = bRep.GetVertex(p);
|
bRep.SetVertex(vert, q);
|
}
|
u += du;
|
}
|
|
if (endcaps)
|
{
|
Vertex vert = biparamFunction(-1, 0);
|
|
int p = (uDivs + 1) * (vDivs + 1) + (uDivs + 1) * 2;
|
|
if (touched)
|
{
|
vert.s = -1;
|
vert.t = 0;
|
}
|
else
|
{
|
Vertex old = bRep.GetVertex(p);
|
vert.s = old.s;
|
vert.t = old.t;
|
}
|
bRep.SetVertex(vert, p);
|
vert = biparamFunction(-1, 1);
|
p++;
|
if (touched)
|
{
|
vert.s = -1;
|
vert.t = 1;
|
}
|
else
|
{
|
Vertex old = bRep.GetVertex(p);
|
vert.s = old.s;
|
vert.t = old.t;
|
}
|
bRep.SetVertex(vert, p);
|
}
|
|
touched = false;
|
|
super.recalculate();
|
|
//System.out.println("BREP TRIMMED? 4 " + bRep.trimmed);
|
// if (!bRep.trimmed)
|
// bRep.Trim(cJME.trim, false, false, mode != 0, false);
|
}
|
|
int uDivs;
|
int vDivs;
|
int minUDivs;
|
int minVDivs;
|
boolean endcaps;
|
}
|