Exemple #1
0
 private void writeCoordIndexAscending(TextWriter stream, Mesh mesh)
 {
     int ii = 0;
       while (ii < mesh.Vertices.Count)
       {
     stream.Write("          ");
     for (int jj = 0; jj < (int)mesh.PolygonMode; jj++)
     {
       stream.Write(ii++);
       stream.Write(" ");
     }
     stream.WriteLine("-1");
       }
 }
        protected override void RenderScene()
        {
            if (mCamera.ProjectionMode != eProjectionMode.Orthographic
            && mViewer.DrawNormalsMode == eDrawNormalsMode.DrawNormals)
              {
            mRenderer.RenderScene(mScene, mCamera, RenderOptions.ShowNormals);
              }
              else
              {
            base.RenderScene();
              }

              if (mActiveEntity == null)
              {
            foreach (Entity lEntity in mScene.Entities)
            {
              foreach (Mesh lMesh in lEntity.Meshes)
              {
            OwnedMesh lOm = lMesh as OwnedMesh;
            if (lOm != null && lOm.Owner == mViewer.ActiveObject)
            {
              mActiveEntity = lEntity;
              goto breakouter;
            }
              }
            }
            breakouter: ;
              }

              if (mActiveEntity != null)
              {
            Mesh lBoundingMesh = new Mesh(PolygonMode.Quads);
            Cuboid lBounds = mActiveEntity.GetBoundingBox();

            lBoundingMesh.AddFace(
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMin, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMin, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMax, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMax, lBounds.ZMax), Color.Red));
            lBoundingMesh.AddFace(
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMin, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMax, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMax, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMin, lBounds.ZMin), Color.Red));
            lBoundingMesh.AddFace(
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMax, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMax, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMax, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMax, lBounds.ZMin), Color.Red));
            lBoundingMesh.AddFace(
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMin, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMin, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMin, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMin, lBounds.ZMax), Color.Red));
            lBoundingMesh.AddFace(
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMin, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMax, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMax, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMax, lBounds.YMin, lBounds.ZMax), Color.Red));
            lBoundingMesh.AddFace(
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMin, lBounds.ZMin), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMin, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMax, lBounds.ZMax), Color.Red),
              new Vertex(new GLTK.Point(lBounds.XMin, lBounds.YMax, lBounds.ZMin), Color.Red));

            lBoundingMesh.RenderMode = RenderMode.Wireframe;

            Entity lBox = new Entity();
            lBox.Transform = mActiveEntity.Transform;
            lBox.Meshes.Add(lBoundingMesh);

            mRenderer.ClearDepthBuffer();
            mRenderer.RenderSingleObject(lBox, RenderOptions.Default);
            mActiveEntity = null;
              }
        }
Exemple #3
0
 private string ImageUrl(Mesh mesh, String filePath)
 {
     string fileDir = Path.GetDirectoryName(filePath);
       string imageDirName = Path.GetFileName(filePath) + "_images";
       string imageDirPath = Path.Combine(fileDir, imageDirName);
       Directory.CreateDirectory(imageDirPath);
       string relUrl = Path.Combine(imageDirName, mesh.Texture + ".png");
       string absUrl = Path.Combine(fileDir, relUrl);
       if (File.Exists(absUrl))
       {
     return relUrl;
       }
       Bitmap bitmap = AbstractRenderer.TextureIdToImage(mesh.Texture);
       bitmap.Save(absUrl);
       return relUrl;
 }
        protected override void RenderMeshInternal(Mesh xiMesh, RenderOptions xiOptions)
        {
            using (ScopedLock lLock = LockContext())
              {
            RenderMode lMode = DefaultRenderMode;
            if (FixedRenderMode != RenderMode.Undefined)
            {
              lMode = FixedRenderMode;
            }
            else if (xiMesh.RenderMode != RenderMode.Undefined)
            {
              lMode = xiMesh.RenderMode;
            }

            switch (lMode)
            {
              case RenderMode.Points:
            Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_POINT);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
            break;

              case RenderMode.Wireframe:
            Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
            break;

              case RenderMode.Filled:
              case RenderMode.TranslucentFilled:
            Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
            break;

              default:
              case RenderMode.Textured:
            Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, xiMesh.Texture);
            break;
            }

            switch (xiMesh.PolygonMode)
            {
              case PolygonMode.Lines:
            Gl.glBegin(Gl.GL_LINES);
            break;
              case PolygonMode.Triangles:
            Gl.glBegin(Gl.GL_TRIANGLES);
            break;
              case PolygonMode.Quads:
            Gl.glBegin(Gl.GL_QUADS);
            break;
              default:
            throw new Exception("Unrecognised polygon type");
            }

            foreach (Vertex lVertex in xiMesh.Vertices)
            {
              if (lMode == RenderMode.TranslucentFilled)
              {
            Gl.glColor4d(
              (double)lVertex.Color.R / 255,
              (double)lVertex.Color.G / 255,
              (double)lVertex.Color.B / 255,
              (double)lVertex.Color.A / 255);
              }
              else
              {
            Gl.glColor3d(
              (double)lVertex.Color.R / 255,
              (double)lVertex.Color.G / 255,
              (double)lVertex.Color.B / 255);
              }

              Gl.glNormal3d(lVertex.Normal.x, lVertex.Normal.y, lVertex.Normal.z);
              Gl.glTexCoord2d(lVertex.TexCoordX, lVertex.TexCoordY);
              Gl.glVertex3d(lVertex.Position.x, lVertex.Position.y, lVertex.Position.z);
            }

            Gl.glEnd();

            if ((xiOptions & RenderOptions.ShowNormals) == RenderOptions.ShowNormals)
            {
              Gl.glBegin(Gl.GL_LINES);

              Gl.glColor3d(0.0, 0.0, 1.0);

              foreach (Vertex lVertex in xiMesh.Vertices)
              {
            Gl.glVertex3d(lVertex.Position.x, lVertex.Position.y, lVertex.Position.z);
            Point lNormalEnd = lVertex.Position + 25 * lVertex.Normal;
            Gl.glVertex3d(lNormalEnd.x, lNormalEnd.y, lNormalEnd.z);
              }

              Gl.glEnd();
            }
              }
        }