public static Vec3Array ToVec3Array(IEnumerable <float> puntos) { Vec3Array array = new Vec3Array(); using (IEnumerator <float> enumer = puntos.GetEnumerator()) { while (true) { if (!enumer.MoveNext()) { return(array); } float x = enumer.Current; if (!enumer.MoveNext()) { return(array); } float y = enumer.Current; if (!enumer.MoveNext()) { return(array); } float z = enumer.Current; array.push_back(new Vec3f(x, y, z)); } } }
private static void initVertexMap(Bone b0, Bone b1, Bone b2, RigGeometry geom, Vec3Array array) { VertexInfluenceMap vim = new VertexInfluenceMap(); vim[b0.getName()].setName(b0.getName()); vim[b1.getName()].setName(b1.getName()); vim[b2.getName()].setName(b2.getName()); for (uint i = 0; i < array.size(); i++) { float val = array[i][0]; //std.cout << val << std.endl; if (val >= -1.0f && val <= 0.0f) { vim[b0.getName()].push_back(/*new VertexIndexWeight(*/ (int)i, 1.0f /*)*/); } else if (val > 0.0f && val <= 1.0f) { vim[b1.getName()].push_back(/*new VertexIndexWeight(*/ (int)i, 1.0f /*)*/); } else if (val > 1.0f) { vim[b2.getName()].push_back(/*new VertexIndexWeight(*/ (int)i, 1.0f /*)*/); } } geom.setInfluenceMap(vim); }
static Geode createAxis() { Geode geode = (new Geode()); Geometry geometry = (new Geometry()); Vec3Array vertices = (new Vec3Array()); vertices.push_back(new Vec3f(0.0f, 0.0f, 0.0f)); vertices.push_back(new Vec3f(1.0f, 0.0f, 0.0f)); vertices.push_back(new Vec3f(0.0f, 0.0f, 0.0f)); vertices.push_back(new Vec3f(0.0f, 1.0f, 0.0f)); vertices.push_back(new Vec3f(0.0f, 0.0f, 0.0f)); vertices.push_back(new Vec3f(0.0f, 0.0f, 1.0f)); geometry.setVertexArray(vertices); Vec4Array colors = (new Vec4Array()); colors.push_back(new Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); colors.push_back(new Vec4f(1.0f, 0.0f, 0.0f, 1.0f)); colors.push_back(new Vec4f(0.0f, 1.0f, 0.0f, 1.0f)); colors.push_back(new Vec4f(0.0f, 1.0f, 0.0f, 1.0f)); colors.push_back(new Vec4f(0.0f, 0.0f, 1.0f, 1.0f)); colors.push_back(new Vec4f(0.0f, 0.0f, 1.0f, 1.0f)); geometry.setColorArray(colors, Array.Binding.BIND_PER_VERTEX); geometry.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.LINES, 0, 6)); geometry.getOrCreateStateSet().setMode(GL.GL_LIGHTING, (uint)false.ToStateAttributeValue()); geode.addDrawable(geometry); return(geode); }
static void Main(string[] args) { const int N = 10; //size of array // Allocate array in memory Vec3[] array = new Vec3[N]; // Assign values into array for (int i = 0; i < N; i++) { array[i] = new Vec3() { X = i, Y = 0, Z = 0 }; } //Build proxy to array (with pointers) Vec3Array A = new Vec3Array(array); // Reference the same pointers as A Vec3Array B = new Vec3Array(A); // Change the original array array[4].X = -4; // Or change via a copy A.PtrArray[5]->Y = -5; // Or assign a new value B[0] = B[9]; // Show contents of array via proxy A Console.WriteLine("{0,-6}|{1,6}|{2,6}|{3,6}|{4,6}", "i", "X", "Y", "Z", "Mag"); for (int i = 0; i < N; i++) { Console.WriteLine("{0,6}|{1,6:F2}|{2,6:F2}|{3,6:F2}|{4,6:F3}", i + 1, A[i].X, A[i].Y, A[i].Z, A[i].Mag); } }
public static Vec3Array ToVec3Array(IEnumerable <Point3d> puntos) { Vec3Array array = new Vec3Array(); foreach (Point3d punto in puntos) { array.push_back(punto.ToVec3f()); } return(array); }
private static Geometry createTesselatedBox2(int nsplit, float size) { Geometry geometry = new Geometry(); Vec3Array vertices = new Vec3Array(); Vec3Array colors = new Vec3Array(); geometry.setVertexArray(vertices); geometry.setColorArray(colors, Array.Binding.BIND_PER_VERTEX); float step = size / nsplit; float s = 0.5f / 4.0f; for (int i = 0; i < nsplit; i++) { float x = -1.0f + i * step; //std.cout << x << std.endl; vertices.push_back(new Vec3f(x, s, s)); vertices.push_back(new Vec3f(x, -s, s)); vertices.push_back(new Vec3f(x, -s, -s)); vertices.push_back(new Vec3f(x, s, -s)); Vec3f c = new Vec3f(0.0f, 0.0f, 0.0f); c[i % 3] = 1.0f; colors.push_back(c); colors.push_back(c); colors.push_back(c); colors.push_back(c); } UIntArray array = new UIntArray(); for (uint i = 0; i < nsplit - 1; i++) { uint base1 = i * 4; array.push_back(base1); array.push_back(base1 + 1); array.push_back(base1 + 4); array.push_back(base1 + 1); array.push_back(base1 + 5); array.push_back(base1 + 4); array.push_back(base1 + 3); array.push_back(base1); array.push_back(base1 + 4); array.push_back(base1 + 7); array.push_back(base1 + 3); array.push_back(base1 + 4); array.push_back(base1 + 5); array.push_back(base1 + 1); array.push_back(base1 + 2); array.push_back(base1 + 2); array.push_back(base1 + 6); array.push_back(base1 + 5); array.push_back(base1 + 2); array.push_back(base1 + 3); array.push_back(base1 + 7); array.push_back(base1 + 6); array.push_back(base1 + 2); array.push_back(base1 + 7); } geometry.addPrimitiveSet(new DrawElementsUInt((uint)PrimitiveSet.Mode.TRIANGLES, array.size(), array.frontPtr())); geometry.getOrCreateStateSet().setMode(GL.GL_LIGHTING, (uint)false.ToStateAttributeValue()); geometry.setUseDisplayList(false); return(geometry); }
public CmdResult Execute(ExtendCmdData cmdData, ref string message) { var mainForm = cmdData.MainForm as Form; var viewForm = cmdData.ViewForm as IViewForm; if (viewForm == null) { return(CmdResult.Cancel); } var osgView = viewForm.View as ZfOsgViewCtrl; var osgObj = osgView.OsgObj; var skelroot = new Skeleton(); // 骨骼动画 skelroot.setDefaultUpdateCallback(); var root = new Bone(); // 骨骼 root.setInvBindMatrixInSkeletonSpace(Matrixd.inverse(Matrixd.translate(-1.0f, 0.0f, 0.0f))); root.setName("root"); var pRootUpdate = new UpdateBone("root"); // 骨骼更新器 pRootUpdate.getStackedTransforms().push_back(new StackedTranslateElement("translate", new Vec3f(-1.0f, 0.0f, 0.0f))); root.setUpdateCallback(pRootUpdate); var right0 = new Bone(); right0.setInvBindMatrixInSkeletonSpace(Matrixd.inverse(Matrixd.translate(0.0f, 0.0f, 0.0f))); right0.setName("right0"); var pRight0Update = new UpdateBone("right0"); pRight0Update.getStackedTransforms().push_back(new StackedTranslateElement("translate", new Vec3f(1.0f, 0.0f, 0.0f))); pRight0Update.getStackedTransforms().push_back(new StackedRotateAxisElement("rotate", new Vec3f(0.0f, 0.0f, 1.0f), 0.0)); right0.setUpdateCallback(pRight0Update); var right1 = new Bone(); right1.setInvBindMatrixInSkeletonSpace(Matrixd.inverse(Matrixd.translate(1.0f, 0.0f, 0.0f))); right1.setName("right1"); var pRight1Update = new UpdateBone("right1"); pRight1Update.getStackedTransforms().push_back(new StackedTranslateElement("translate", new Vec3f(1.0f, 0.0f, 0.0f))); pRight1Update.getStackedTransforms().push_back(new StackedRotateAxisElement("rotate", new Vec3f(0.0f, 0.0f, 1.0f), 0.0)); right1.setUpdateCallback(pRight1Update); root.addChild(right0); right0.addChild(right1); skelroot.addChild(root); Group scene = new Group(); BasicAnimationManager manager = new BasicAnimationManager(); scene.setUpdateCallback(manager); Animation anim = new Animation(); { var keys0 = new FloatKeyframeContainer(); // 关键帧容器 keys0.push_back(new FloatKeyframe(0.0, 0.0f)); keys0.push_back(new FloatKeyframe(3.0, (float)MathUtil.PI_2)); keys0.push_back(new FloatKeyframe(6.0, (float)MathUtil.PI_2)); var sampler = new FloatLinearSampler(); // 线性采样器 sampler.setKeyframeContainer(keys0); var channel = new FloatLinearChannel(sampler); // 通道 channel.setName("rotate"); channel.setTargetName("right0"); anim.addChannel(channel); } { var keys1 = new FloatKeyframeContainer(); // 关键帧容器 keys1.push_back(new FloatKeyframe(0.0, 0.0f)); keys1.push_back(new FloatKeyframe(3.0, 0.0f)); keys1.push_back(new FloatKeyframe(6.0, (float)MathUtil.PI_2)); var sampler = new FloatLinearSampler(); // 线性采样器 sampler.setKeyframeContainer(keys1); var channel = new FloatLinearChannel(sampler); // 通道 channel.setName("rotate"); channel.setTargetName("right1"); anim.addChannel(channel); } manager.registerAnimation(anim); manager.buildTargetReference(); // let's start ! manager.playAnimation(anim); // we will use local data from the skeleton MatrixTransform rootTransform = new MatrixTransform(); rootTransform.setMatrix(Matrixf.rotate((float)MathUtil.PI_2, new Vec3f(1.0f, 0.0f, 0.0f))); right0.addChild(createAxis()); right0.setDataVariance(Osg.Object.DataVariance.DYNAMIC); right1.addChild(createAxis()); right1.setDataVariance(Osg.Object.DataVariance.DYNAMIC); MatrixTransform trueroot = new MatrixTransform(); //trueroot.setMatrix(new Matrixf(root.getMatrixInBoneSpace().ptr())); trueroot.setMatrix(root.getMatrixInBoneSpace()); trueroot.addChild(createAxis()); trueroot.addChild(skelroot); trueroot.setDataVariance(Osg.Object.DataVariance.DYNAMIC); rootTransform.addChild(trueroot); scene.addChild(rootTransform); RigGeometry geom = createTesselatedBox(4, 4.0f); Geode geode = new Geode(); geode.Name = "2"; geode.addDrawable(geom); skelroot.addChild(geode); Vec3Array src = new Vec3Array(geom.getSourceGeometry().getVertexArray()); geom.setDataVariance(Osg.Object.DataVariance.DYNAMIC); initVertexMap(root, right0, right1, geom, src); scene.Name = "1"; osgObj.AddOrReplaceModel("Models", scene); osgObj.SetView(ViewMode.ShowAll); return(CmdResult.Succeed); }
/// <summary> /// Crea una escena de ejemplo. /// </summary> private void CreateSampleScene() { //The geode containing our shape Geode geode = new Geode(); ////Our shape: a capsule, it could have been any other geometry (a box, plane, cylinder etc.) //Capsule myCapsule = new Capsule(new Vec3f(), 1, 2); ////Our shape drawable //ShapeDrawable capsuledrawable = new ShapeDrawable(myCapsule); //geode.addDrawable(capsuledrawable); // create POINTS { Geometry pointsGeom = new Geometry(); Vec3Array vertices = new Vec3Array(); vertices.push_back(new Vec3f(-1.02168f, -2.15188e-09f, 0.885735f)); vertices.push_back(new Vec3f(-0.976368f, -2.15188e-09f, 0.832179f)); vertices.push_back(new Vec3f(-0.873376f, 9.18133e-09f, 0.832179f)); vertices.push_back(new Vec3f(-0.836299f, -2.15188e-09f, 0.885735f)); vertices.push_back(new Vec3f(-0.790982f, 9.18133e-09f, 0.959889f)); pointsGeom.setVertexArray(vertices); Vec4Array colors = new Vec4Array(); colors.push_back(new Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); pointsGeom.setColorArray(colors); pointsGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); Vec3Array normals = new Vec3Array(); normals.push_back(new Vec3f(0.0f, -1.0f, 0.0f)); pointsGeom.setNormalArray(normals); pointsGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); pointsGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.POINTS, 0, (int)vertices.size())); geode.addDrawable(pointsGeom); } // create LINES { // create Geometry object to store all the vertices and lines primitive. Geometry linesGeom = new Geometry(); // this time we'll preallocate the vertex array to the size we // need and then simple set them as array elements, 8 points // makes 4 line segments. Vec3Array vertices = new Vec3Array(8); vertices.set(0, new Vec3f(-1.13704f, -2.15188e-09f, 0.40373f)); vertices.set(1, new Vec3f(-0.856897f, -2.15188e-09f, 0.531441f)); vertices.set(2, new Vec3f(-0.889855f, -2.15188e-09f, 0.444927f)); vertices.set(3, new Vec3f(-0.568518f, -2.15188e-09f, 0.40373f)); vertices.set(4, new Vec3f(-1.00933f, -2.15188e-09f, 0.370773f)); vertices.set(5, new Vec3f(-0.716827f, -2.15188e-09f, 0.292498f)); vertices.set(6, new Vec3f(-1.07936f, 9.18133e-09f, 0.317217f)); vertices.set(7, new Vec3f(-0.700348f, 9.18133e-09f, 0.362533f)); // pass the created vertex array to the points geometry object. linesGeom.setVertexArray(vertices); // set the colors as before, plus using the above Vec4Array colors = new Vec4Array(); colors.push_back(new Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); linesGeom.setColorArray(colors); linesGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); // set the normal in the same way color. Vec3Array normals = new Vec3Array(); normals.push_back(new Vec3f(0.0f, -1.0f, 0.0f)); linesGeom.setNormalArray(normals); linesGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, linesGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.LINES, 0, 8)); // add the points geometry to the geode. geode.addDrawable(linesGeom); } // create LINE_STRIP { // create Geometry object to store all the vertices and lines primitive. Geometry linesGeom = new Geometry(); // this time we'll preallocate the vertex array to the size // and then use an iterator to fill in the values, a bit perverse // but does demonstrate that we have just a standard std::vector underneath. Vec3Array vertices = new Vec3Array(); vertices.push_back(new Vec3f(-0.0741545f, -2.15188e-09f, 0.416089f)); vertices.push_back(new Vec3f(0.234823f, -2.15188e-09f, 0.259541f)); vertices.push_back(new Vec3f(0.164788f, -2.15188e-09f, 0.366653f)); vertices.push_back(new Vec3f(-0.0288379f, -2.15188e-09f, 0.333695f)); vertices.push_back(new Vec3f(-0.0453167f, -2.15188e-09f, 0.280139f)); // pass the created vertex array to the points geometry object. linesGeom.setVertexArray(vertices); // set the colors as before, plus using the above Vec4Array colors = new Vec4Array(); colors.push_back(new Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); linesGeom.setColorArray(colors); linesGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); // set the normal in the same way color. Vec3Array normals = new Vec3Array(); normals.push_back(new Vec3f(0.0f, -1.0f, 0.0f)); linesGeom.setNormalArray(normals); linesGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, linesGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.LINE_STRIP, 0, 5)); // add the points geometry to the geode. geode.addDrawable(linesGeom); } // create LINE_LOOP { // create Geometry object to store all the vertices and lines primitive. Geometry linesGeom = new Geometry(); // this time we'll a C arrays to initialize the vertices. Vec3f[] myCoords = { new Vec3f(0.741546f, -2.15188e-09f, 0.453167f), new Vec3f(0.840418f, -2.15188e-09f, 0.304858f), new Vec3f(1.12468f, -2.15188e-09f, 0.300738f), new Vec3f(1.03816f, 9.18133e-09f, 0.453167f), new Vec3f(0.968129f, -2.15188e-09f, 0.337815f), new Vec3f(0.869256f, -2.15188e-09f, 0.531441f) }; int numCoords = myCoords.Length; Vec3Array vertices = new Vec3Array(new Vec3Vector(myCoords)); // pass the created vertex array to the points geometry object. linesGeom.setVertexArray(vertices); // set the colors as before, plus using the above Vec4Array colors = new Vec4Array(); colors.push_back(new Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); linesGeom.setColorArray(colors); linesGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); // set the normal in the same way color. Vec3Array normals = new Vec3Array(); normals.push_back(new Vec3f(0.0f, -1.0f, 0.0f)); linesGeom.setNormalArray(normals); linesGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, linesGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.LINE_LOOP, 0, numCoords)); // add the points geometry to the geode. geode.addDrawable(linesGeom); } // now we'll stop creating separate normal and color arrays // since we are using the same values all the time, we'll just // share the same ColorArray and NormalArrays.. // set the colors as before, use a ref_ptr rather than just // standard C pointer, as that in the case of it not being // assigned it will still be cleaned up automatically. Vec4Array shared_colors = new Vec4Array(); shared_colors.push_back(new Vec4f(1.0f, 1.0f, 0.0f, 1.0f)); // same trick for shared normal. Vec3Array shared_normals = new Vec3Array(); shared_normals.push_back(new Vec3f(0.0f, -1.0f, 0.0f)); // Note on vertex ordering. // According to the OpenGL diagram vertices should be specified in a clockwise direction. // In reality you need to specify coords for polygons in a anticlockwise direction // for their front face to be pointing towards you; get this wrong and you could // find back face culling removing the wrong faces of your models. The OpenGL diagram // is just plain wrong, but it's a nice diagram so we'll keep it for now! // create POLYGON { // create Geometry object to store all the vertices and lines primitive. Geometry polyGeom = new Geometry(); // this time we'll use C arrays to initialize the vertices. // note, anticlockwise ordering. // note II, OpenGL polygons must be convex, planar polygons, otherwise // undefined results will occur. If you have concave polygons or ones // that cross over themselves then use the osgUtil::Tessellator to fix // the polygons into a set of valid polygons. Vec3f[] myCoords = { new Vec3f(-1.0464f, 0.0f, -0.193626f), new Vec3f(-1.0258f, 0.0f, -0.26778f), new Vec3f(-0.807461f, 0.0f, -0.181267f), new Vec3f(-0.766264f, 0.0f, -0.0576758f), new Vec3f(-0.980488f, 0.0f, -0.094753f) }; int numCoords = myCoords.Length; Vec3Array vertices = new Vec3Array(new Vec3Vector(myCoords)); // pass the created vertex array to the points geometry object. polyGeom.setVertexArray(vertices); // use the shared color array. polyGeom.setColorArray(shared_colors); polyGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); // use the shared normal array. polyGeom.setNormalArray(shared_normals); polyGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, polyGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.POLYGON, 0, numCoords)); //printTriangles("Polygon", polyGeom); // add the points geometry to the geode. geode.addDrawable(polyGeom); } // create QUADS { // create Geometry object to store all the vertices and lines primitive. Geometry polyGeom = new Geometry(); // note, anticlockwise ordering. Vec3f[] myCoords = { new Vec3f(0.0247182f, 0.0f, -0.156548f), new Vec3f(0.0247182f, 0.0f, -0.00823939f), new Vec3f(-0.160668f, 0.0f, -0.0453167f), new Vec3f(-0.222464f, 0.0f, -0.13183f), new Vec3f(0.238942f, 0.0f, -0.251302f), new Vec3f(0.333696f, 0.0f, 0.0329576f), new Vec3f(0.164788f, 0.0f, -0.0453167f), new Vec3f(0.13595f, 0.0f, -0.255421f) }; int numCoords = myCoords.Length; Vec3Array vertices = new Vec3Array(new Vec3Vector(myCoords)); // pass the created vertex array to the points geometry object. polyGeom.setVertexArray(vertices); // use the shared color array. polyGeom.setColorArray(shared_colors); polyGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); // use the shared normal array. polyGeom.setNormalArray(shared_normals); polyGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, polyGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.QUADS, 0, numCoords)); //printTriangles("Quads", *polyGeom); // add the points geometry to the geode. geode.addDrawable(polyGeom); } // create QUAD_STRIP { // create Geometry object to store all the vertices and lines primitive. Geometry polyGeom = new Geometry(); // note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. Vec3f[] myCoords = { new Vec3f(0.733306f, -2.15188e-09f, -0.0741545f), new Vec3f(0.758024f, -2.15188e-09f, -0.205985f), new Vec3f(0.885735f, -2.15188e-09f, -0.0576757f), new Vec3f(0.885735f, -2.15188e-09f, -0.214224f), new Vec3f(0.964009f, 9.18133e-09f, -0.0370773f), new Vec3f(1.0464f, 9.18133e-09f, -0.173027f), new Vec3f(1.11232f, -2.15188e-09f, 0.0123591f), new Vec3f(1.12468f, 9.18133e-09f, -0.164788f), }; int numCoords = myCoords.Length; Vec3Array vertices = new Vec3Array(new Vec3Vector(myCoords)); // pass the created vertex array to the points geometry object. polyGeom.setVertexArray(vertices); // use the shared color array. polyGeom.setColorArray(shared_colors); polyGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); // use the shared normal array. polyGeom.setNormalArray(shared_normals); polyGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, polyGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.QUAD_STRIP, 0, numCoords)); //printTriangles("Quads strip", *polyGeom); // add the points geometry to the geode. geode.addDrawable(polyGeom); } // create TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN all in one Geometry/ { // create Geometry object to store all the vertices and lines primitive. Geometry polyGeom = new Geometry(); // note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. Vec3f[] myCoords = { // TRIANGLES 6 vertices, v0..v5 // note in anticlockwise order. new Vec3f(-1.12056f, -2.15188e-09f, -0.840418f), new Vec3f(-0.95165f, -2.15188e-09f, -0.840418f), new Vec3f(-1.11644f, 9.18133e-09f, -0.716827f), // note in anticlockwise order. new Vec3f(-0.840418f, 9.18133e-09f, -0.778623f), new Vec3f(-0.622074f, 9.18133e-09f, -0.613835f), new Vec3f(-1.067f, 9.18133e-09f, -0.609715f), // TRIANGLE STRIP 6 vertices, v6..v11 // note defined top point first, // then anticlockwise for the next two points, // then alternating to bottom there after. new Vec3f(-0.160668f, -2.15188e-09f, -0.531441f), new Vec3f(-0.160668f, -2.15188e-09f, -0.749785f), new Vec3f(0.0617955f, 9.18133e-09f, -0.531441f), new Vec3f(0.168908f, -2.15188e-09f, -0.753905f), new Vec3f(0.238942f, -2.15188e-09f, -0.531441f), new Vec3f(0.280139f, -2.15188e-09f, -0.823939f), // TRIANGLE FAN 5 vertices, v12..v16 // note defined in anticlockwise order. new Vec3f(0.844538f, 9.18133e-09f, -0.712708f), new Vec3f(1.0258f, 9.18133e-09f, -0.799221f), new Vec3f(1.03816f, -2.15188e-09f, -0.692109f), new Vec3f(0.988727f, 9.18133e-09f, -0.568518f), new Vec3f(0.840418f, -2.15188e-09f, -0.506723f), }; int numCoords = myCoords.Length; Vec3Array vertices = new Vec3Array(new Vec3Vector(myCoords)); // pass the created vertex array to the points geometry object. polyGeom.setVertexArray(vertices); // use the shared color array. polyGeom.setColorArray(shared_colors); polyGeom.setColorBinding(Geometry.AttributeBinding.BIND_OVERALL); // use the shared normal array. polyGeom.setNormalArray(shared_normals); polyGeom.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, polyGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.TRIANGLES, 0, 6)); polyGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.TRIANGLE_STRIP, 6, 6)); polyGeom.addPrimitiveSet(new DrawArrays((uint)PrimitiveSet.Mode.TRIANGLE_FAN, 12, 5)); // polygon stipple StateSet stateSet = new StateSet(); polyGeom.setStateSet(stateSet); //# if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) // PolygonStipple* polygonStipple = new PolygonStipple; // stateSet.setAttributeAndModes(polygonStipple, StateAttribute.Values.OVERRIDE | StateAttribute.Values.ON); //#endif //printTriangles("Triangles/Strip/Fan", *polyGeom); // add the points geometry to the geode. geode.addDrawable(polyGeom); } this.root.addChild(geode); }