summaryrefslogtreecommitdiff
path: root/graphics/asymptote/drawsurface.h
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-12-28 03:01:00 +0000
committerNorbert Preining <norbert@preining.info>2021-12-28 03:01:00 +0000
commitecdf859b6ce481abfd530425dcf6f0f764bd0001 (patch)
tree13bc161dc046876ac6c92fce5f9f5034ba9aa573 /graphics/asymptote/drawsurface.h
parent790995b7e79697514364450bf9c04f1b8d500838 (diff)
CTAN sync 202112280300
Diffstat (limited to 'graphics/asymptote/drawsurface.h')
-rw-r--r--graphics/asymptote/drawsurface.h160
1 files changed, 133 insertions, 27 deletions
diff --git a/graphics/asymptote/drawsurface.h b/graphics/asymptote/drawsurface.h
index 9a8010a8d0..9ece42a818 100644
--- a/graphics/asymptote/drawsurface.h
+++ b/graphics/asymptote/drawsurface.h
@@ -40,9 +40,9 @@ protected:
double metallic;
double fresnel0;
bool invisible;
+ size_t centerIndex;
Interaction interaction;
bool billboard;
- size_t centerIndex;
triple Min,Max;
int digits;
@@ -68,7 +68,7 @@ public:
centerIndex=0;
}
- drawSurface(const vm::array& g, size_t ncontrols, triple center,
+ drawSurface(const vm::array& g, size_t ncontrols, const triple& center,
bool straight, const vm::array&p, double opacity,
double shininess, double metallic, double fresnel0,
const vm::array &pens, Interaction interaction, int digits,
@@ -125,6 +125,19 @@ public:
center=t*s->center;
}
+ double renderResolution() {
+ double prerender=settings::getSetting<double>("prerender");
+ if(prerender <= 0.0) return 0.0;
+ prerender=1.0/prerender;
+ double perspective=gl::orthographic ? 0.0 : 1.0/gl::zmax;
+ double s=perspective ? Min.getz()*perspective : 1.0; // Move to glrender
+ triple b(gl::xmin,gl::ymin,gl::zmin);
+ triple B(gl::xmax,gl::ymax,gl::zmax);
+ pair size3(s*(B.getx()-b.getx()),s*(B.gety()-b.gety()));
+ pair size2(gl::fullWidth,gl::fullHeight);
+ return prerender*size3.length()/size2.length();
+ }
+
virtual ~drawSurface() {}
bool is3D() {return true;}
@@ -132,11 +145,11 @@ public:
class drawBezierPatch : public drawSurface {
public:
-#ifdef HAVE_GL
+#ifdef HAVE_LIBGLM
BezierPatch S;
#endif
- drawBezierPatch(const vm::array& g, triple center, bool straight,
+ drawBezierPatch(const vm::array& g, const triple& center, bool straight,
const vm::array&p, double opacity, double shininess,
double metallic, double fresnel0, const vm::array &pens,
Interaction interaction, int digits, bool primitive) :
@@ -157,7 +170,7 @@ public:
}
bool write(prcfile *out, unsigned int *, double, groupsmap&);
- bool write(jsfile *out);
+ bool write(abs3Doutfile *out);
void render(double, const triple& b, const triple& B,
double perspective, bool remesh);
@@ -166,11 +179,11 @@ public:
class drawBezierTriangle : public drawSurface {
public:
-#ifdef HAVE_GL
+#ifdef HAVE_LIBGLM
BezierTriangle S;
#endif
- drawBezierTriangle(const vm::array& g, triple center, bool straight,
+ drawBezierTriangle(const vm::array& g, const triple& center, bool straight,
const vm::array&p, double opacity, double shininess,
double metallic, double fresnel0, const vm::array &pens,
Interaction interaction, int digits, bool primitive) :
@@ -191,7 +204,7 @@ public:
}
bool write(prcfile *out, unsigned int *, double, groupsmap&);
- bool write(jsfile *out);
+ bool write(abs3Doutfile *out);
void render(double, const triple& b, const triple& B,
double perspective, bool remesh);
@@ -382,11 +395,11 @@ public:
virtual void P(triple& t, double x, double y, double z);
- virtual bool write(prcfile *out, unsigned int *, double, groupsmap&) {
+ virtual bool write(prcfile *out, unsigned int *, double, groupsmap&) override {
return true;
}
- virtual bool write(jsfile *out) {return true;}
+ virtual bool write(abs3Doutfile *out) override {return true;}
virtual void transformedbounds(const double*, bbox3&) {}
virtual void transformedratio(const double*, pair&,
@@ -409,7 +422,7 @@ public:
void P(triple& t, double x, double y, double z);
bool write(prcfile *out, unsigned int *, double, groupsmap&);
- bool write(jsfile *out);
+ bool write(abs3Doutfile *out);
drawElement *transformed(const double* t) {
return new drawSphere(t,this);
@@ -428,10 +441,10 @@ public:
drawCylinder(const double* t, const drawCylinder *s) :
drawPRC(t,s), core(s->core) {}
- bool write(prcfile *out, unsigned int *, double, groupsmap&);
- bool write(jsfile *out);
+ bool write(prcfile *out, unsigned int *, double, groupsmap&) override;
+ bool write(abs3Doutfile *out) override;
- drawElement *transformed(const double* t) {
+ drawElement *transformed(const double* t) override {
return new drawCylinder(t,this);
}
};
@@ -446,10 +459,10 @@ public:
drawDisk(const double* t, const drawDisk *s) :
drawPRC(t,s) {}
- bool write(prcfile *out, unsigned int *, double, groupsmap&);
- bool write(jsfile *out);
+ bool write(prcfile *out, unsigned int *, double, groupsmap&) override;
+ bool write(abs3Doutfile *out) override;
- drawElement *transformed(const double* t) {
+ drawElement *transformed(const double* t) override {
return new drawDisk(t,this);
}
};
@@ -483,9 +496,9 @@ public:
g[i]=t*s->g[i];
}
- bool write(jsfile *out);
+ bool write(abs3Doutfile *out) override;
- drawElement *transformed(const double* t) {
+ drawElement *transformed(const double* t) override {
return new drawTube(t,this);
}
};
@@ -493,19 +506,24 @@ public:
class drawBaseTriangles : public drawElement {
protected:
-#ifdef HAVE_GL
+#ifdef HAVE_LIBGLM
Triangles R;
bool transparent;
#endif
+public:
+ bool billboard;
size_t nP;
triple* P;
+ triple center;
size_t nN;
triple* N;
size_t nI;
size_t Ni;
uint32_t (*PI)[3];
uint32_t (*NI)[3];
+ size_t centerIndex;
+ Interaction interaction;
triple Min,Max;
@@ -513,8 +531,21 @@ protected:
static const string outofrange;
public:
+ void init() {
+#ifdef HAVE_LIBOSMESA
+ billboard=false;
+#else
+ billboard=interaction == BILLBOARD;
+#endif
+ centerIndex=0;
+ }
+
drawBaseTriangles(const vm::array& v, const vm::array& vi,
- const vm::array& n, const vm::array& ni) {
+ const triple& center,
+ const vm::array& n, const vm::array& ni,
+ Interaction interaction) : center(center),
+ interaction(interaction) {
+ init();
nP=checkArray(&v);
P=new(UseGC) triple[nP];
for(size_t i=0; i < nP; ++i)
@@ -560,8 +591,45 @@ public:
} else Ni=0;
}
+#ifdef HAVE_LIBGLM
+ drawBaseTriangles(const vertexBuffer& vb, const triple& center,
+ Interaction interaction, bool isColor,
+ const triple& Min, const triple& Max) :
+ transparent(false),
+ nP(isColor ? vb.Vertices.size() : vb.vertices.size()), center(center),
+ nN(nP), nI(vb.indices.size()/3), Ni(0),
+ interaction(interaction), Min(Min), Max(Max) {
+ init();
+ assert(vb.indices.size() % 3 == 0);
+ P=new(UseGC) triple[nP];
+ N=new(UseGC) triple[nN];
+ if(!isColor) {
+ for (size_t i=0; i < vb.vertices.size(); ++i) {
+ P[i]=triple(vb.vertices[i].position[0], vb.vertices[i].position[1], vb.vertices[i].position[2]);
+ N[i]=triple(vb.vertices[i].normal[0], vb.vertices[i].normal[1], vb.vertices[i].normal[2]);
+ }
+ }
+ else {
+ for (size_t i=0; i < vb.Vertices.size(); ++i) {
+ P[i]=triple(vb.Vertices[i].position[0], vb.Vertices[i].position[1], vb.Vertices[i].position[2]);
+ N[i]=triple(vb.Vertices[i].normal[0], vb.Vertices[i].normal[1], vb.Vertices[i].normal[2]);
+ }
+ }
+
+ PI=new(UseGC) uint32_t[nI][3];
+ for (size_t i=0; i < nI; ++i) {
+ PI[i][0]=vb.indices[3 * i];
+ PI[i][1]=vb.indices[3 * i + 1];
+ PI[i][2]=vb.indices[3 * i + 2];
+ }
+ NI=PI;
+ }
+#endif
+
drawBaseTriangles(const double* t, const drawBaseTriangles *s) :
- drawElement(s->KEY), nP(s->nP), nN(s->nN), nI(s->nI), Ni(s->Ni) {
+ drawElement(s->KEY),
+ nP(s->nP), nN(s->nN), nI(s->nI), Ni(s->Ni), interaction(s->interaction) {
+ init();
P=new(UseGC) triple[nP];
for(size_t i=0; i < nP; i++)
P[i]=t*s->P[i];
@@ -574,6 +642,8 @@ public:
PIi[j]=sPIi[j];
}
+ center=t*s->center;
+
if(nN) {
N=new(UseGC) triple[nN];
if(t == NULL) {
@@ -609,6 +679,11 @@ public:
void ratio(const double* t, pair &b, double (*m)(double, double),
double fuzz, bool &first);
+ void meshinit() {
+ if(billboard)
+ centerIndex=centerindex(center);
+ }
+
virtual ~drawBaseTriangles() {}
drawElement *transformed(const double* t) {
@@ -633,13 +708,14 @@ class drawTriangles : public drawBaseTriangles {
bool invisible;
public:
- drawTriangles(const vm::array& v, const vm::array& vi,
+ drawTriangles(const vm::array& v, const vm::array& vi, const triple& center,
const vm::array& n, const vm::array& ni,
const vm::array&p, double opacity, double shininess,
double metallic, double fresnel0,
- const vm::array& c, const vm::array& ci) :
- drawBaseTriangles(v,vi,n,ni), opacity(opacity), shininess(shininess),
- metallic(metallic), fresnel0(fresnel0) {
+ const vm::array& c, const vm::array& ci,
+ Interaction interaction) :
+ drawBaseTriangles(v,vi,center,n,ni,interaction), opacity(opacity),
+ shininess(shininess), metallic(metallic), fresnel0(fresnel0) {
if(checkArray(&p) != 3)
reportError(need3pens);
@@ -680,6 +756,36 @@ public:
specular=rgba(vm::read<camp::pen>(p,2));
}
+#ifdef HAVE_LIBGLM
+ drawTriangles(vertexBuffer const& vb, const triple &center, bool isColor,
+ prc::RGBAColour diffuse,
+ prc::RGBAColour emissive,
+ prc::RGBAColour specular,
+ double opacity,
+ double shininess,
+ double metallic,
+ double fresnel0, Interaction interaction,
+ bool invisible,
+ const triple& Min, const triple& Max) :
+ drawBaseTriangles(vb,center,interaction,isColor,Min,Max),
+ nC(isColor ? vb.Vertices.size() : 0), C(nullptr),
+ CI(isColor ? PI : nullptr),
+ Ci(isColor ? Ni : 0),
+ diffuse(diffuse), emissive(emissive), specular(specular),
+ opacity(opacity), shininess(shininess),
+ metallic(metallic), fresnel0(fresnel0), invisible(invisible) {
+ if(isColor) {
+ C=new(UseGC) prc::RGBAColour[nC];
+ for(size_t i=0; i < nC; ++i) {
+ C[i].Set(vb.Vertices[i].color[0],
+ vb.Vertices[i].color[1],
+ vb.Vertices[i].color[2],
+ vb.Vertices[i].color[3]);
+ }
+ }
+ }
+#endif
+
drawTriangles(const double* t, const drawTriangles *s) :
drawBaseTriangles(t,s), nC(s->nC),
diffuse(s->diffuse), emissive(s->emissive),
@@ -707,7 +813,7 @@ public:
double perspective, bool remesh);
bool write(prcfile *out, unsigned int *, double, groupsmap&);
- bool write(jsfile *out);
+ bool write(abs3Doutfile *out);
drawElement *transformed(const double* t) {
return new drawTriangles(t,this);