Search in sources :

Example 1 with InstanceTransformType

use of maspack.render.RenderInstances.InstanceTransformType in project artisynth_core by artisynth.

the class GL2Viewer method drawPoints.

@Override
public void drawPoints(RenderObject robj, int gidx, RenderInstances rinst) {
    boolean selecting = isSelecting();
    boolean hasColors = ((robj.hasColors() || rinst.hasColors()) && hasVertexColoring());
    boolean useColors = hasColors && !selecting && (myActiveColor == ActiveColor.DEFAULT);
    boolean useHSV = isHSVColorInterpolationEnabled();
    // update state
    maybeUpdateState(gl);
    // if use vertex colors, get them to track glColor
    int savedShading = 0;
    if (useColors) {
        savedShading = enableVertexColoring(useHSV);
    }
    boolean useDisplayList = (!selecting || !hasColors) && (!robj.isTransient());
    GL2VersionedObject gvo = null;
    boolean compile = true;
    if (useDisplayList) {
        RenderInstancesKey key = new RenderInstancesKey(rinst.getIdentifier(), robj.getIdentifier(), DrawType.POINTS, gidx);
        // get snapshot of version information
        RenderInstancesFingerprint fingerprint = new RenderInstancesFingerprint(rinst.getVersionInfo(), robj.getVersionInfo());
        gvo = myGLResources.getVersionedObject(key);
        if (gvo == null || gvo.disposeInvalid(gl)) {
            gvo = myGLResources.allocateVersionedObject(gl, key, fingerprint);
            compile = true;
        } else {
            compile = !(gvo.compareExchangeFingerPrint(fingerprint));
        }
    }
    if (compile) {
        if (gvo != null) {
            gvo.beginCompile(gl);
        }
        // prevent writes to robj and rinst
        robj.readLock();
        rinst.readLock();
        int ninstances = rinst.numInstances();
        int[] instances = rinst.getInstances();
        int ipos = rinst.getInstanceTypeOffset();
        int tpos = rinst.getInstanceTransformOffset();
        int cpos = rinst.getInstanceColorOffset();
        int spos = rinst.getInstanceScaleOffset();
        int stride = rinst.getInstanceStride();
        InstanceTransformType[] type = RenderInstances.getTransformTypes();
        boolean hasInstanceScales = rinst.hasScales();
        boolean hasInstanceColors = useColors && rinst.hasColors();
        for (int i = 0; i < ninstances; ++i) {
            int iidx = instances[ipos];
            int tidx = instances[tpos];
            int cidx = instances[cpos];
            int sidx = instances[spos];
            gl.glPushMatrix();
            // transform
            switch(type[iidx]) {
                case AFFINE:
                    {
                        AffineTransform3d aff = rinst.getAffine(tidx);
                        mulTransform(gl, aff);
                        break;
                    }
                case FRAME:
                    {
                        RigidTransform3d frame = rinst.getFrame(tidx);
                        mulTransform(gl, frame);
                        break;
                    }
                case POINT:
                    {
                        float[] trans = rinst.getPoint(tidx);
                        gl.glTranslatef(trans[0], trans[1], trans[2]);
                        break;
                    }
            }
            if (hasInstanceScales && (sidx >= 0)) {
                Double s = rinst.getScale(sidx);
                gl.glScaled(s, s, s);
            }
            if (hasInstanceColors && (cidx >= 0)) {
                byte[] c = rinst.getColor(cidx);
                gl.glColor4ub(c[0], c[1], c[2], c[3]);
            }
            // draw raw object
            drawRawPoints(gl, robj, gidx, 0, robj.numPoints(gidx), robj.hasNormals(), !hasInstanceColors && useColors, !selecting & robj.hasTextureCoords(), useHSV);
            gl.glPopMatrix();
            ipos += stride;
            tpos += stride;
            cpos += stride;
            spos += stride;
        }
        robj.readUnlock();
        rinst.readUnlock();
        if (gvo != null) {
            gvo.endCompile(gl);
            gvo.draw(gl);
        }
    } else {
        gvo.draw(gl);
    }
    // disable color tracking
    if (useColors) {
        disableVertexColoring(useHSV, savedShading);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) InstanceTransformType(maspack.render.RenderInstances.InstanceTransformType) Point(java.awt.Point) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 2 with InstanceTransformType

use of maspack.render.RenderInstances.InstanceTransformType in project artisynth_core by artisynth.

the class GL2Viewer method drawTriangles.

@Override
public void drawTriangles(RenderObject robj, int gidx, RenderInstances rinst) {
    boolean selecting = isSelecting();
    boolean hasColors = ((robj.hasColors() || rinst.hasColors()) && hasVertexColoring());
    boolean useColors = hasColors && !selecting && (myActiveColor == ActiveColor.DEFAULT);
    boolean useHSV = isHSVColorInterpolationEnabled();
    // update state
    maybeUpdateState(gl);
    // if use vertex colors, get them to track glColor
    int savedShading = 0;
    if (useColors) {
        savedShading = enableVertexColoring(useHSV);
    }
    boolean useDisplayList = (!selecting || !hasColors) && (!robj.isTransient());
    GL2VersionedObject gvo = null;
    boolean compile = true;
    if (useDisplayList) {
        RenderInstancesKey key = new RenderInstancesKey(rinst.getIdentifier(), robj.getIdentifier(), DrawType.TRIANGLES, gidx);
        // get snapshot of version information
        RenderInstancesFingerprint fingerprint = new RenderInstancesFingerprint(rinst.getVersionInfo(), robj.getVersionInfo());
        gvo = myGLResources.getVersionedObject(key);
        if (gvo == null || gvo.disposeInvalid(gl)) {
            gvo = myGLResources.allocateVersionedObject(gl, key, fingerprint);
            compile = true;
        } else {
            compile = !(gvo.compareExchangeFingerPrint(fingerprint));
        }
    }
    if (compile) {
        if (gvo != null) {
            gvo.beginCompile(gl);
        }
        // prevent writes to robj and rinst
        robj.readLock();
        rinst.readLock();
        int ninstances = rinst.numInstances();
        int[] instances = rinst.getInstances();
        int ipos = rinst.getInstanceTypeOffset();
        int tpos = rinst.getInstanceTransformOffset();
        int cpos = rinst.getInstanceColorOffset();
        int spos = rinst.getInstanceScaleOffset();
        int stride = rinst.getInstanceStride();
        InstanceTransformType[] type = RenderInstances.getTransformTypes();
        boolean hasInstanceScales = rinst.hasScales();
        boolean hasInstanceColors = useColors && rinst.hasColors();
        for (int i = 0; i < ninstances; ++i) {
            int iidx = instances[ipos];
            int tidx = instances[tpos];
            int cidx = instances[cpos];
            int sidx = instances[spos];
            gl.glPushMatrix();
            // transform
            switch(type[iidx]) {
                case AFFINE:
                    {
                        AffineTransform3d aff = rinst.getAffine(tidx);
                        mulTransform(gl, aff);
                        break;
                    }
                case FRAME:
                    {
                        RigidTransform3d frame = rinst.getFrame(tidx);
                        mulTransform(gl, frame);
                        break;
                    }
                case POINT:
                    {
                        float[] trans = rinst.getPoint(tidx);
                        gl.glTranslatef(trans[0], trans[1], trans[2]);
                        break;
                    }
            }
            if (hasInstanceScales && (sidx >= 0)) {
                Double s = rinst.getScale(sidx);
                gl.glScaled(s, s, s);
            }
            if (hasInstanceColors && (cidx >= 0)) {
                byte[] c = rinst.getColor(cidx);
                gl.glColor4ub(c[0], c[1], c[2], c[3]);
            }
            // draw raw object
            drawRawTriangles(gl, robj, gidx, 0, robj.numTriangles(gidx), robj.hasNormals(), !hasInstanceColors && useColors, !selecting & robj.hasTextureCoords(), useHSV);
            gl.glPopMatrix();
            ipos += stride;
            tpos += stride;
            cpos += stride;
            spos += stride;
        }
        robj.readUnlock();
        rinst.readUnlock();
        if (gvo != null) {
            gvo.endCompile(gl);
            gvo.draw(gl);
        }
    } else {
        gvo.draw(gl);
    }
    // disable color tracking
    if (useColors) {
        disableVertexColoring(useHSV, savedShading);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) InstanceTransformType(maspack.render.RenderInstances.InstanceTransformType) Point(java.awt.Point) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 3 with InstanceTransformType

use of maspack.render.RenderInstances.InstanceTransformType in project artisynth_core by artisynth.

the class StlRenderer method drawTriangles.

@Override
public void drawTriangles(RenderObject robj, int gidx, RenderInstances rinst) {
    int idx = 0;
    int[] buff = rinst.getInstances();
    InstanceTransformType[] types = InstanceTransformType.values();
    rinst.readLock();
    robj.readLock();
    for (int i = 0; i < rinst.numInstances(); ++i) {
        pushModelMatrix();
        int type = buff[idx++];
        int tidx = buff[idx++];
        int sidx = buff[idx++];
        InstanceTransformType tt = types[type];
        switch(tt) {
            case POINT:
                {
                    // point
                    float[] pnt = rinst.getPoint(tidx);
                    translateModelMatrix(pnt[0], pnt[1], pnt[2]);
                    break;
                }
            case FRAME:
                {
                    RigidTransform3d frame = rinst.getFrame(tidx);
                    mulModelMatrix(frame);
                    break;
                }
            case AFFINE:
                {
                    AffineTransform3d affine = rinst.getAffine(tidx);
                    mulModelMatrix(affine);
                    break;
                }
        }
        Double s = rinst.getScale(sidx);
        if (s != null && s.doubleValue() != 1.0) {
            scaleModelMatrix(s);
        }
        drawTriangles(robj);
        popModelMatrix();
    }
    robj.readUnlock();
    rinst.readUnlock();
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) InstanceTransformType(maspack.render.RenderInstances.InstanceTransformType) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 4 with InstanceTransformType

use of maspack.render.RenderInstances.InstanceTransformType in project artisynth_core by artisynth.

the class GL2Viewer method drawLines.

@Override
public void drawLines(RenderObject robj, int gidx, RenderInstances rinst) {
    boolean selecting = isSelecting();
    boolean hasColors = ((robj.hasColors() || rinst.hasColors()) && hasVertexColoring());
    boolean useColors = hasColors && !selecting && (myActiveColor == ActiveColor.DEFAULT);
    boolean useHSV = isHSVColorInterpolationEnabled();
    // update state
    maybeUpdateState(gl);
    // if use vertex colors, get them to track glColor
    int savedShading = 0;
    if (useColors) {
        savedShading = enableVertexColoring(useHSV);
    }
    boolean useDisplayList = (!selecting || !hasColors) && (!robj.isTransient());
    GL2VersionedObject gvo = null;
    boolean compile = true;
    if (useDisplayList) {
        RenderInstancesKey key = new RenderInstancesKey(rinst.getIdentifier(), robj.getIdentifier(), DrawType.LINES, gidx);
        // get snapshot of version information
        RenderInstancesFingerprint fingerprint = new RenderInstancesFingerprint(rinst.getVersionInfo(), robj.getVersionInfo());
        gvo = myGLResources.getVersionedObject(key);
        if (gvo == null || gvo.disposeInvalid(gl)) {
            gvo = myGLResources.allocateVersionedObject(gl, key, fingerprint);
            compile = true;
        } else {
            compile = !(gvo.compareExchangeFingerPrint(fingerprint));
        }
    }
    if (compile) {
        if (gvo != null) {
            gvo.beginCompile(gl);
        }
        // prevent writes to robj and rinst
        robj.readLock();
        rinst.readLock();
        int ninstances = rinst.numInstances();
        int[] instances = rinst.getInstances();
        int ipos = rinst.getInstanceTypeOffset();
        int tpos = rinst.getInstanceTransformOffset();
        int cpos = rinst.getInstanceColorOffset();
        int spos = rinst.getInstanceScaleOffset();
        int stride = rinst.getInstanceStride();
        InstanceTransformType[] type = RenderInstances.getTransformTypes();
        boolean hasInstanceScales = rinst.hasScales();
        boolean hasInstanceColors = useColors && rinst.hasColors();
        for (int i = 0; i < ninstances; ++i) {
            int iidx = instances[ipos];
            int tidx = instances[tpos];
            int cidx = instances[cpos];
            int sidx = instances[spos];
            gl.glPushMatrix();
            // transform
            switch(type[iidx]) {
                case AFFINE:
                    {
                        AffineTransform3d aff = rinst.getAffine(tidx);
                        mulTransform(gl, aff);
                        break;
                    }
                case FRAME:
                    {
                        RigidTransform3d frame = rinst.getFrame(tidx);
                        mulTransform(gl, frame);
                        break;
                    }
                case POINT:
                    {
                        float[] trans = rinst.getPoint(tidx);
                        gl.glTranslatef(trans[0], trans[1], trans[2]);
                        break;
                    }
            }
            if (hasInstanceScales && (sidx >= 0)) {
                Double s = rinst.getScale(sidx);
                gl.glScaled(s, s, s);
            }
            if (hasInstanceColors && (cidx >= 0)) {
                byte[] c = rinst.getColor(cidx);
                gl.glColor4ub(c[0], c[1], c[2], c[3]);
            }
            // draw raw object
            drawRawLines(gl, robj, gidx, 0, robj.numLines(gidx), robj.hasNormals(), !hasInstanceColors && useColors, !selecting & robj.hasTextureCoords(), useHSV);
            gl.glPopMatrix();
            ipos += stride;
            tpos += stride;
            cpos += stride;
            spos += stride;
        }
        robj.readUnlock();
        rinst.readUnlock();
        if (gvo != null) {
            gvo.endCompile(gl);
            gvo.draw(gl);
        }
    } else {
        gvo.draw(gl);
    }
    // disable color tracking
    if (useColors) {
        disableVertexColoring(useHSV, savedShading);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) InstanceTransformType(maspack.render.RenderInstances.InstanceTransformType) Point(java.awt.Point) AffineTransform3d(maspack.matrix.AffineTransform3d)

Aggregations

AffineTransform3d (maspack.matrix.AffineTransform3d)4 RigidTransform3d (maspack.matrix.RigidTransform3d)4 InstanceTransformType (maspack.render.RenderInstances.InstanceTransformType)4 Point (java.awt.Point)3