Exemplo n.º 1
0
 public void CreateMeshNew(ModularMesh mesh)
 {
     if (leftOutline)
     {
         rightOutline = new Polyline(
             leftOutline.VerticesToParameter(startParameter),
             new Vertex[1] {
             leftOutline.VertexAtParameter(startParameter)
         },
             leftOutline.Inset(width).VerticesBetweenParameter(startParameter, endParameter),
             new Vertex[1] {
             leftOutline.VertexAtParameter(endParameter)
         },
             leftOutline.VerticesFromParameter(endParameter));
         //rightOutline = new Polyline(
         //    leftOutline.VerticesToParameter(startParameter),
         //    leftOutline.Inset(width).VerticesBetweenParameter(startParameter, endParameter),
         //    leftOutline.VerticesFromParameter(endParameter));
         laneSurface = new TriangleStrip(leftOutline, rightOutline, mesh, MaterialManager.GetMaterial("diffuseGray"));
     }
     else
     {
         Debug.Log("LeftOutline missing");
     }
 }
Exemplo n.º 2
0
        public static IMultiPatch EnvelopeToBoundingBox(IEnvelope2 ienvelope2_0)
        {
            object value = Missing.Value;
            double double_;
            double double_2;
            double double_3;
            double double_4;

            ienvelope2_0.QueryCoords(out double_, out double_2, out double_3, out double_4);
            double              zMin               = ienvelope2_0.ZMin;
            double              zMax               = ienvelope2_0.ZMax;
            IMultiPatch         multiPatch         = new MultiPatch() as IMultiPatch;
            IGeometryCollection geometryCollection = multiPatch as IGeometryCollection;
            IPointCollection    pointCollection    = new TriangleStrip();

            Utils3D.MakeZMAware(pointCollection as IGeometry, true);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_2, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_2, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_4, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_4, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_4, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_4, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMax), ref value, ref value);
            geometryCollection.AddGeometry(pointCollection as IGeometry, ref value, ref value);
            return(multiPatch);
        }
Exemplo n.º 3
0
 public void CreateMesh(ModularMesh mesh)
 {
     if (leftOutline)
     {
         rightOutline = leftOutline.Inset(width);
         laneSurface  = new TriangleStrip(leftOutline, rightOutline, mesh, MaterialManager.GetMaterial("diffuseGray"));
     }
 }
Exemplo n.º 4
0
    public void UpdateMesh(ModularMesh mesh)
    {
        if (laneSurface != null)
        {
            laneSurface.RemoveFromMesh(mesh, MaterialManager.GetMaterial("diffuseGray"));
        }

        rightOutline = leftOutline.Inset(width);
        laneSurface  = new TriangleStrip(leftOutline, rightOutline, mesh, MaterialManager.GetMaterial("diffuseGray"));
    }
Exemplo n.º 5
0
 public void CreateMeshNew(ModularMesh mesh)
 {
     if (leftOutline)
     {
         rightOutline = new Polyline(
             leftOutline.VerticesToParameter(startParameter),
             leftOutline.Inset(width).VerticesBetweenParameter(startParameter, endParameter),
             leftOutline.VerticesFromParameter(endParameter));
         laneSurface = new TriangleStrip(leftOutline, rightOutline, mesh, MaterialManager.GetMaterial("diffuseGray"));
     }
 }
Exemplo n.º 6
0
 public void CreateMesh(ModularMesh mesh)
 {
     if (leftOutline)
     {
         rightOutline = leftOutline.Inset(width);
         laneSurface  = new TriangleStrip(leftOutline, rightOutline, mesh, MaterialManager.GetMaterial("diffuseBrown"));
     }
     else
     {
         Debug.Log("LeftOutline missing!");
     }
 }
Exemplo n.º 7
0
    public void CreateMesh(ModularMesh mesh)
    {
        if (leftOutline)
        {
            curbedge     = leftOutline.Translate(Vector3.up * height);
            rightOutline = curbedge.Inset(width);

            curbFace    = new TriangleStrip(leftOutline, curbedge, mesh, MaterialManager.GetMaterial("diffuseCheckerboard"));
            curbSurface = new TriangleStrip(curbedge, rightOutline, mesh, MaterialManager.GetMaterial("diffuseCheckerboard"));
        }
        else
        {
            Debug.Log("LeftOutline missing");
        }
    }
Exemplo n.º 8
0
    public void UpdateMesh(ModularMesh mesh)
    {
        if (curbFace != null)
        {
            curbFace.RemoveFromMesh(mesh, MaterialManager.GetMaterial("diffuseCheckerboard"));
        }
        if (curbSurface != null)
        {
            curbSurface.RemoveFromMesh(mesh, MaterialManager.GetMaterial("diffuseCheckerboard"));
        }

        curbedge     = leftOutline.Translate(Vector3.up * height);
        rightOutline = curbedge.Inset(width);

        curbFace    = new TriangleStrip(leftOutline, curbedge, mesh, MaterialManager.GetMaterial("diffuseCheckerboard"));
        curbSurface = new TriangleStrip(curbedge, rightOutline, mesh, MaterialManager.GetMaterial("diffuseCheckerboard"));
    }
Exemplo n.º 9
0
        public void TestGetAreaOk()
        {
            TriangleStrip ts = new TriangleStrip(
                new List <Vertex>
            {
                new Vertex(0, 0),
                new Vertex(2, 0),
                new Vertex(2, 2),
                new Vertex(4, 2),
            }
                );

            ShapeProcessor processor = new ShapeProcessor();
            double         actual    = processor.GetArea(ts);
            double         expected  = 4;

            Assert.IsTrue(Math.Abs(expected - actual) < 0.000001);    // <-- Doubles are not precise! :-(
        }
Exemplo n.º 10
0
        public bool ImportFromWavefront(string filename)
        {
            Log.Info(string.Format("Loading file {0} into memory buffer", filename));
            byte[] buffer = null;
            using (var file = File.OpenRead(filename))
            {
                buffer = new byte[file.Length];
                file.Read(buffer, 0, buffer.Length);
            } if (buffer == null)
            {
                Log.Error("Failed to create memory buffer");
                return false;
            }
            MemoryStream stream = new MemoryStream(buffer);
            StreamReader reader = new StreamReader(stream);

            WavefrontOBJ.Object[] objects = new WavefrontOBJ.Object[1] { new WavefrontOBJ.Object() { faces_start_index = 0 } };
            List<WavefrontOBJ.Face> faces = new List<WavefrontOBJ.Face>();
            List<Vector3> vertex_coords = new List<Vector3>();
            List<Vector2> texture_coords = new List<Vector2>();
            List<Vector3> normals = new List<Vector3>();
            Dictionary<string, int> material_names = new Dictionary<string, int>();
            material_names.Add("default", 0);
            int selected_material = 0;
            bool default_object = true;
            bool default_object_processed = false;
            bool has_normals = false;
            bool has_texcoords = false;

            Log.Info("Begin parsing Wavefront Object data from buffer");
            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine().Trim();
                if (line.StartsWith("# "))
                {
                    Log.Info(line);
                    continue;
                }
                if (line.StartsWith("o "))
                {
                    // if this is the first object token, use the default object
                    if (default_object) default_object = false;
                    else
                    {
                        Log.Warn(@"Support for multiple wavefront objects per mesh not implemented.
                                   Meshes can only accept a single wavefront object. Continuing, but only using first object!");
                        if (!default_object_processed)
                        {
                            objects[0].faces_count = faces.Count;
                            default_object_processed = true;
                        }
                    }
                }
                else if (line.StartsWith("v "))
                {
                    Vector3 vertex;
                    if (!WavefrontExtensions.TryParseVector3(out vertex, line)) return false;
                    vertex_coords.Add(vertex);
                }
                else if (line.StartsWith("vt "))
                {
                    has_texcoords = true;
                    Vector2 texcoord;
                    if (!WavefrontExtensions.TryParseVector2(out texcoord, line)) return false;
                    texture_coords.Add(texcoord);
                }
                else if (line.StartsWith("vn "))
                {
                    has_normals = true;
                    Vector3 normal;
                    if (!WavefrontExtensions.TryParseVector3(out normal, line)) return false;
                    normals.Add(normal);
                }
                else if (line.StartsWith("usemtl "))
                {
                    string name = line.Replace("usemtl ", "").Trim();
                    if (!material_names.ContainsKey(name)) material_names.Add(name, material_names.Count);
                    selected_material = material_names[name];
                }
                else if (line.StartsWith("f "))
                {
                    WavefrontOBJ.Face face;
                    if (!WavefrontOBJ.Face.TryParse(line, out face))
                    {
                        Log.Error(string.Format("Error parsing line: {0}", line));
                        return false;
                    }
                    else
                    {
                        face.material_id = selected_material;
                        faces.Add(face);
                    }
                }
                else Log.Warn(string.Format("Unsupported format found while parsing line: {0}", line));
            }
            if (!default_object_processed)
            {
                objects[0].faces_count = faces.Count;
                default_object_processed = true;
            }
            Log.Info("Partial success... finished parsing Wavefront Object data from buffer");

            List<Triangle> triangle_list = new List<Triangle>(faces.Count);
            List<Vector3> vertex_coordiantes = new List<Vector3>(vertex_coords.Count);
            List<Vector2> texture_coordinates = new List<Vector2>(vertex_coords.Count);
            List<Vector3> vertex_normals = new List<Vector3>(vertex_coords.Count);
            List<string> tokens = new List<string>();

            for (int i = 0; i < faces.Count; i++)
            {
                Triangle triangle = new Triangle() { MaterialID = faces[i].material_id };
                for (int token = 0; token < 3; ++token)
                {
                    if (!tokens.Contains(faces[i].GetToken(token)))
                    {
                        triangle.Vertex1 = (ushort)vertex_coordiantes.Count;
                        tokens.Add(faces[i].GetToken(0));
                        vertex_coordiantes.Add(vertex_coords[faces[i].vertex_indices[token] - 1]);
                        texture_coordinates.Add(faces[i].has_texcoord ? texture_coords[faces[i].texcoord_indices[token] - 1] : Vector2.Zero);
                        vertex_normals.Add(faces[i].has_normals ? normals[faces[i].normal_indices[token] - 1] : Vector3.Zero);
                    }
                    else
                    {
                        triangle.Vertex1 = (ushort)tokens.IndexOf(faces[i].GetToken(token));
                    }
                }
                triangle_list.Add(triangle);
            }

            List<TriangleStrip> strips = new List<TriangleStrip>(material_names.Count);
            foreach (var material in material_names)
            {
                var material_faces = triangle_list.Where(x => x.MaterialID == material.Value).Select(x => x.AsEnumerable<ushort>());
                List<ushort> tris = new List<ushort>(material_faces.Count() * 3);
                foreach (var item in material_faces)
                {
                    tris.AddRange(item.ToArray());
                }
                if (tris.Count > 0)
                {
                    Adjacencies stripper = new Adjacencies(tris.ToArray());
                    strips.Add(new TriangleStrip() { MaterialID = (ushort)material.Value, Indices = stripper.GenerateTriangleStrip() });
                }
            }
            this.Coordinates = vertex_coordiantes.ToArray();
            this.TextureCoordinates = texture_coordinates.ToArray();
            this.Normals = vertex_normals.ToArray();

            this.Primitives = new MeshPrimitive[strips.Count];

            Log.Info("Parsing shader groups from triangle strips...");
            TriangleStrip combined_strip = new TriangleStrip() { Indices = new ushort[0] };
            ushort offset = 0;
            for (int i = 0; i < strips.Count; ++i)
            {
                TriangleStrip.Append(ref combined_strip, strips[i]);
                this.Primitives[i] = new MeshPrimitive(offset, (ushort)(combined_strip.Indices.Length - offset)) { shader_index = (ushort)i };
                Log.Info(string.Format(@"ShaderGroup[ {0} ] {{ Start = {1}, Length = {2} }}", i, offset, (combined_strip.Indices.Length - offset).ToString()));
                offset = (ushort)combined_strip.Indices.Length;

            }
            this.Indices = combined_strip.Indices;
            if (!has_texcoords)
            {
                Log.Warn("No texture coordinates found while parsing Wavefront file..." +
                        "\nGenerating uv coordinates from vertex positions (flat mapping)");
                this.GenerateTexCoords();
            }
            if (!has_normals)
            {
                Log.Warn("No normals found while parsing Wavefront file..." +
                        "\nGenerating normals...");
                this.GenerateNormals();
            }
            Log.Info("Generating tangent space vectors...");
            this.GenerateTangentSpaceVectors();
            Log.Info("Success, import finished! Returning true from ImportFromWavefront();");
            return true;
        }
Exemplo n.º 11
0
    public void Render()
    {
        GraphicsHelperGl g = new GraphicsHelperGl();

        Gl.glPushMatrix();
        g.Translate(Offset);
        switch (PrimitiveType)
        {
        case UnitPart.PrimitiveTypeEnum.Triangles:
        {
            Gl.glBegin(Gl.GL_TRIANGLES);
            foreach (Primitive primitive in Primitives)
            {
                Triangle triangle = primitive as Triangle;
                g.Normal(triangle.Vertices[0].Normal);
                g.TexCoord(triangle.Vertices[0].TextureCoords);
                g.Vertex(triangle.Vertices[0].Pos);

                g.Normal(triangle.Vertices[1].Normal);
                g.TexCoord(triangle.Vertices[1].TextureCoords);
                g.Vertex(triangle.Vertices[1].Pos);

                g.Normal(triangle.Vertices[2].Normal);
                g.TexCoord(triangle.Vertices[2].TextureCoords);
                g.Vertex(triangle.Vertices[2].Pos);
            }
            Gl.glEnd();
            break;
        }

        case UnitPart.PrimitiveTypeEnum.Quads:
        {
            Gl.glBegin(Gl.GL_QUADS);
            foreach (Primitive primitive in Primitives)
            {
                Quad quad = primitive as Quad;
                g.Normal(quad.Vertices[0].Normal);
                g.TexCoord(quad.Vertices[0].TextureCoords);
                g.Vertex(quad.Vertices[0].Pos);

                g.Normal(quad.Vertices[1].Normal);
                g.TexCoord(quad.Vertices[1].TextureCoords);
                g.Vertex(quad.Vertices[1].Pos);

                g.Normal(quad.Vertices[2].Normal);
                g.TexCoord(quad.Vertices[2].TextureCoords);
                g.Vertex(quad.Vertices[2].Pos);

                g.Normal(quad.Vertices[3].Normal);
                g.TexCoord(quad.Vertices[3].TextureCoords);
                g.Vertex(quad.Vertices[3].Pos);
            }
            Gl.glEnd();
            break;
        }

        case UnitPart.PrimitiveTypeEnum.TriangleStrips:
        {
            foreach (Primitive primitive in Primitives)
            {
                TriangleStrip trianglestrip = primitive as TriangleStrip;
                Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
                foreach (Vertex vertex in trianglestrip.Vertices)
                {
                    g.Normal(vertex.Normal);
                    g.TexCoord(vertex.TextureCoords);
                    g.Vertex(vertex.Pos);
                }
                Gl.glEnd();
            }
            break;
        }
        }

        foreach (UnitPart childunitpart in Children)
        {
            childunitpart.Render();
        }
        Gl.glPopMatrix();
    }
Exemplo n.º 12
0
        public static IGroupElement CreateFacadesFromPolygon(IFeature ifeature_0, IFeature3DProperties ifeature3DProperties_0, clsTextureGroup clsTextureGroup_0, ISurface isurface_0, string string_0, IPolygon ipolygon_0, bool bool_0)
        {
            IGroupElement groupElement = null;
            IGroupElement result;

            try
            {
                IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;
                IGroupElement       groupElement2      = new GroupElement() as IGroupElement;
                if (modFacades.m_limitAngle == 0.0)
                {
                    modFacades.m_limitAngle = 0.5235987666666666;
                }
                IGeometry geometry = null;
                if (ifeature_0 != null)
                {
                    if (ifeature3DProperties_0 != null && bool_0)
                    {
                        ifeature3DProperties_0.ApplyFeatureProperties(ifeature_0, out geometry, false);
                    }
                    else
                    {
                        geometry = ifeature_0.Shape;
                    }
                }
                else if (ipolygon_0 != null)
                {
                    geometry = ipolygon_0;
                }
                if (geometry == null)
                {
                    result = null;
                    return(result);
                }
                if (!(geometry is IMultiPatch))
                {
                }
                IEnvelope         envelope         = geometry.Envelope;
                double            num              = envelope.ZMin;
                ISpatialReference spatialReference = BuildingProperty.Scene.SpatialReference;
                geometry.Project(spatialReference);
                string a = num.ToString();
                if (a.Equals("非数字"))
                {
                    num = 0.0;
                }
                double num2 = 0.0;
                if (ifeature3DProperties_0 != null)
                {
                    I3DProperties i3DProperties = ifeature3DProperties_0 as I3DProperties;
                    if (i3DProperties.OffsetExpressionString.Length > 0)
                    {
                        try
                        {
                            num2 = Convert.ToDouble(i3DProperties.OffsetExpressionString);
                        }
                        catch
                        {
                        }
                    }
                    if (geometry is IPolygon)
                    {
                        num += num2;
                    }
                }
                IGeometryCollection geometryCollection = geometry as IGeometryCollection;
                int geometryCount = geometryCollection.GeometryCount;
                int num3;
                if (geometry is IMultiPatch)
                {
                    geometryCount = geometryCollection.GeometryCount;
                    num3          = geometryCollection.GeometryCount * 2 / 3;
                    modFacades.m_extrusionHeight = geometry.Envelope.ZMax - geometry.Envelope.ZMin;
                }
                else
                {
                    num3          = 0;
                    geometryCount = geometryCollection.GeometryCount;
                }
                if (modFacades.m_extrusionHeight < 1.0)
                {
                    modFacades.m_extrusionHeight = 1.0;
                }
                IPoint point = null;
                double num4  = 0.0;
                double num5  = 0.0;
                double num6  = 0.0;
                object value = Missing.Value;
                for (int i = num3; i < geometryCount; i++)
                {
                    IGeometry        geometry2    = geometryCollection.get_Geometry(i);
                    esriGeometryType geometryType = geometry2.GeometryType;
                    if (geometryType == esriGeometryType.esriGeometryRing || geometryType == esriGeometryType.esriGeometryPolyline)
                    {
                        IPointCollection pointCollection = geometry2 as IPointCollection;
                        int pointCount = pointCollection.PointCount;
                        if (pointCount >= 2)
                        {
                            int                 num7 = 0;
                            int                 num8 = 1;
                            bool                flag = false;
                            IPointCollection    pointCollection2;
                            double              m;
                            IMultiPatch         multiPatch;
                            IGeometryCollection geometryCollection2;
                            IZAware             iZAware;
                            IMAware             iMAware;
                            IElement            element;
                            while (!flag)
                            {
                                bool flag2 = false;
                                while (num8 < pointCount && !flag2)
                                {
                                    if (num8 - num7 == 1)
                                    {
                                        IPoint point2 = pointCollection.get_Point(num7);
                                        point = pointCollection.get_Point(num8);
                                        num5  = point.X - point2.X;
                                        num6  = point.Y - point2.Y;
                                        num4  = Math.Sqrt(num5 * num5 + num6 * num6);
                                        if (isurface_0 != null)
                                        {
                                            num  = isurface_0.get_Z(point.X, point.Y);
                                            num += num2;
                                        }
                                    }
                                    else
                                    {
                                        IPoint point2 = point;
                                        double num9   = num5;
                                        double num10  = num6;
                                        point = pointCollection.get_Point(num8);
                                        if (isurface_0 != null)
                                        {
                                            num  = isurface_0.get_Z(point.X, point.Y);
                                            num += num2;
                                        }
                                        num5 = point.X - point2.X;
                                        num6 = point.Y - point2.Y;
                                        double num11 = Math.Sqrt(num9 * num9 + num10 * num10);
                                        double num12 = Math.Sqrt(num5 * num5 + num6 * num6);
                                        double num13 = (num9 * num5 + num10 * num6) / (num11 * num12);
                                        if (num13 < Math.Cos(modFacades.m_limitAngle))
                                        {
                                            flag2 = true;
                                            break;
                                        }
                                        num4 += num12;
                                    }
                                    num8++;
                                }
                                if (flag2)
                                {
                                    num8--;
                                }
                                else
                                {
                                    num8--;
                                }
                                pointCollection2 = new TriangleStrip();
                                double num14 = 0.0;
                                for (int j = num7; j <= num8; j++)
                                {
                                    if (j > 0)
                                    {
                                        IPoint point2 = point;
                                        point  = pointCollection.get_Point(j);
                                        num5   = point.X - point2.Y;
                                        num6   = point.Y - point2.Y;
                                        num14 += Math.Sqrt(num5 * num5 + num6 * num6);
                                    }
                                    else
                                    {
                                        point = pointCollection.get_Point(j);
                                    }
                                    point.Z = num;
                                    m       = 0.0;
                                    encode3DProperties.PackTexture2D(num14 / num4, 0.0, out m);
                                    point.M = m;
                                    IClone clone = point as IClone;
                                    pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                                    point.Z = num + modFacades.m_extrusionHeight;
                                    m       = 0.0;
                                    encode3DProperties.PackTexture2D(num14 / num4, -1.0, out m);
                                    point.M = m;
                                    pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                                }
                                multiPatch          = new MultiPatch() as IMultiPatch;
                                geometryCollection2 = (multiPatch as IGeometryCollection);
                                iZAware             = (multiPatch as IZAware);
                                iZAware.ZAware      = true;
                                iMAware             = (multiPatch as IMAware);
                                iMAware.MAware      = true;
                                geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                                if (clsTextureGroup_0 != null)
                                {
                                    int index = modFacades.FindTextureByAspect(clsTextureGroup_0, num4 / modFacades.m_extrusionHeight);
                                    element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.Symbols[index], string_0);
                                }
                                else
                                {
                                    element = modFacades.CreateElement(multiPatch, null, string_0);
                                }
                                if (element != null)
                                {
                                    groupElement2.AddElement(element);
                                }
                                num7 = num8;
                                num8 = num7 + 1;
                                if (num7 >= pointCount - 1)
                                {
                                    flag = true;
                                }
                            }
                            IVector3D vector3D = new Vector3D() as IVector3D;
                            vector3D.XComponent = 0.0;
                            vector3D.YComponent = 0.0;
                            vector3D.ZComponent = 1.0;
                            m = 0.0;
                            encode3DProperties.PackNormal(vector3D, out m);
                            pointCollection2 = new Ring();
                            for (int j = 0; j <= pointCount - 1; j++)
                            {
                                IPoint point3 = pointCollection.get_Point(j);
                                point3.Z = num + modFacades.m_extrusionHeight;
                                point3.M = 0.0;
                                IClone clone = point3 as IClone;
                                pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value);
                            }
                            IRing ring = pointCollection2 as IRing;
                            ring.Close();
                            multiPatch          = new MultiPatch() as IMultiPatch;
                            geometryCollection2 = (multiPatch as IGeometryCollection);
                            iZAware             = (multiPatch as IZAware);
                            iZAware.ZAware      = true;
                            iMAware             = (multiPatch as IMAware);
                            iMAware.MAware      = true;
                            geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value);
                            multiPatch.PutRingType(pointCollection2 as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing);
                            if (clsTextureGroup_0 != null)
                            {
                                element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.RoofSymbol, string_0 + ";ROOFCOLOR=" + clsTextureGroup_0.RoofColorRGB.ToString());
                            }
                            else
                            {
                                element = modFacades.CreateElement(multiPatch, null, string_0 + ";ROOFCOLOR=1");
                            }
                            if (element != null)
                            {
                                groupElement2.AddElement(element);
                            }
                        }
                    }
                }
                if (groupElement2 != null)
                {
                    IElementProperties elementProperties = groupElement2 as IElementProperties;
                    elementProperties.Name = string_0;
                }
                groupElement = groupElement2;
                result       = groupElement;
                return(result);
            }
            catch
            {
            }
            result = groupElement;
            return(result);
        }
Exemplo n.º 13
0
    UnitPart LoadUnitPart(byte[] data, int offset)
    {
        UnitPart unitpart = new UnitPart();

        _S3OPiece s3opiece = new _S3OPiece();

        s3opiece = ReadBinary(s3opiece, data, offset) as _S3OPiece;
        LogFile.GetInstance().WriteLine("name offset: " + s3opiece.name);
        LogFile.GetInstance().WriteLine(ReadString(data, Convert.ToInt32(s3opiece.name)));
        unitpart.Name   = ReadString(data, Convert.ToInt32(s3opiece.name));
        unitpart.Offset = new Vector3(s3opiece.xoffset, s3opiece.yoffset, s3opiece.zoffset);
        //unitpart.Vertices = new Vertex[s3opiece.numVertices];
        //unitpart.Primitives = new int[s3opiece.vertexTableSize];
        if (s3opiece.primitiveType == 0)
        {
            unitpart.PrimitiveType = UnitPart.PrimitiveTypeEnum.Triangles;
        }
        else if (s3opiece.primitiveType == 1)
        {
            unitpart.PrimitiveType = UnitPart.PrimitiveTypeEnum.TriangleStrips;
        }
        else if (s3opiece.primitiveType == 2)
        {
            unitpart.PrimitiveType = UnitPart.PrimitiveTypeEnum.Quads;
        }
        int numvertices = (int)s3opiece.numVertices;

        LogFile.GetInstance().WriteLine("num vertices: " + numvertices);
        Vertex[] Vertices = new Vertex[numvertices];
        //if (unitpart.Name == "barrel")
        //{
        for (int i = 0; i < numvertices; i++)
        {
            uint       vertexoffset = (uint)(s3opiece.vertices + i * 8 * sizeof(float)); // note to self: kindof a  hack to hardcode the 8
            _S3OVertex s3overtex    = new _S3OVertex();
            s3overtex = ReadBinary(s3overtex, data, (int)vertexoffset) as _S3OVertex;
            Vertex vertex = new Vertex();
            vertex.Pos    = new Vector3(s3overtex.xpos, s3overtex.ypos, s3overtex.zpos);
            vertex.Normal = new Vector3(s3overtex.xnormal, s3overtex.ynormal, s3overtex.znormal);
            vertex.Normal.Normalize();
            vertex.TextureCoords = new Vector2(s3overtex.texu, s3overtex.texv);
            Vertices[i]          = vertex;
            //      Console.WriteLine(vertex.Pos.ToString() + " " + vertex.Normal.ToString() + " " + vertex.TextureCoords.ToString() );
        }
        //}
        int vertextablesize = (int)s3opiece.vertexTableSize;

        LogFile.GetInstance().WriteLine("vertextablesize: " + vertextablesize);

        switch (unitpart.PrimitiveType)
        {
        case UnitPart.PrimitiveTypeEnum.Triangles:
        {
            unitpart.Primitives = new Primitive[vertextablesize / 3];
            for (int i = 0; i < vertextablesize; i += 3)
            {
                //if (unitpart.Name == "barrel")
                //{
                Triangle triangle    = new Triangle();
                int      vertexindex = (int)BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + i * sizeof(uint)));
                triangle.Vertices[0] = Vertices[vertexindex];
                //Console.WriteLine("vertex " + vertexindex);

                vertexindex          = (int)BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + (i + 1) * sizeof(uint)));
                triangle.Vertices[1] = Vertices[vertexindex];
                // Console.WriteLine("vertex " + vertexindex);

                vertexindex          = (int)BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + (i + 2) * sizeof(uint)));
                triangle.Vertices[2] = Vertices[vertexindex];
                //  Console.WriteLine("vertex " + vertexindex);

                unitpart.Primitives[i / 3] = triangle;
                //}
            }
            LogFile.GetInstance().WriteLine((vertextablesize / 3).ToString() + " triangles");
            break;
        }

        case UnitPart.PrimitiveTypeEnum.TriangleStrips:
        {
            List <Primitive> primitives = new List <Primitive>();
            for (int i = 0; i < vertextablesize;)
            {
                List <Vertex> thistrianglestripvertices = new List <Vertex>();
                while (i < vertextablesize)
                {
                    uint vertexindex = BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + i * sizeof(uint)));
                    if (vertexindex == UInt32.MaxValue)
                    {
                        break;
                    }
                    thistrianglestripvertices.Add(Vertices[(int)vertexindex]);
                    i++;
                }
                TriangleStrip trianglestrip = new TriangleStrip();
                trianglestrip.Vertices = thistrianglestripvertices.ToArray();
                primitives.Add(trianglestrip);
            }
            unitpart.Primitives = primitives.ToArray();
            LogFile.GetInstance().WriteLine(unitpart.Primitives.GetLength(0) + " triangle strips");
            break;
        }

        case UnitPart.PrimitiveTypeEnum.Quads:
        {
            unitpart.Primitives = new Primitive[vertextablesize / 4];
            for (int i = 0; i < vertextablesize; i += 4)
            {
                Quad quad        = new Quad();
                int  vertexindex = (int)BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + i * sizeof(uint)));
                quad.Vertices[0]           = Vertices[vertexindex];
                vertexindex                = (int)BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + (i + 1) * sizeof(uint)));
                quad.Vertices[1]           = Vertices[vertexindex];
                vertexindex                = (int)BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + (i + 2) * sizeof(uint)));
                quad.Vertices[2]           = Vertices[vertexindex];
                vertexindex                = (int)BitConverter.ToUInt32(data, (int)(s3opiece.vertexTable + (i + 3) * sizeof(uint)));
                quad.Vertices[3]           = Vertices[vertexindex];
                unitpart.Primitives[i / 4] = quad;
            }
            LogFile.GetInstance().WriteLine(unitpart.Primitives.GetLength(0) + " quads");
            break;
        }
        }

        for (int i = 0; i < (int)s3opiece.numChilds; i++)
        {
            //mdlobject.Children.Add(LoadMdlObject(data, (int)( s3opiece.childs + i * sizeof(uint) )));
            uint     childoffset   = BitConverter.ToUInt32(data, (int)s3opiece.childs + i * sizeof(uint));
            UnitPart childunitpart = LoadUnitPart(data, (int)childoffset);
            unitpart.Children.Add(childunitpart);
        }
        return(unitpart);
    }
Exemplo n.º 14
0
        public static IMultiPatch Cylinder(IPoint ipoint_0, double double_0, double double_1, double double_2, double double_3, double double_4, bool bool_0, bool bool_1)
        {
            double              num                = 36.0;
            object              value              = Missing.Value;
            double              num2               = (double_2 - double_1) / num;
            double              num3               = double_2 - double_1;
            IMultiPatch         multiPatch         = new MultiPatch() as IMultiPatch;
            IGeometryCollection geometryCollection = multiPatch as IGeometryCollection;
            IPointCollection    pointCollection    = new TriangleStrip();
            IVector3D           vector3D           = new Vector3D() as IVector3D;
            IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;

            for (double num4 = double_2; num4 <= double_1; num4 += -num2)
            {
                double num5 = Utils3D.DegreesToRadians(num4);
                vector3D.PolarSet(-num5, 0.0, double_0);
                IPoint point = new Point();
                point.X = ipoint_0.X + vector3D.XComponent;
                point.Y = ipoint_0.Y + vector3D.YComponent;
                point.Z = double_3;
                double num6 = (num4 - double_1) / num3;
                if (bool_0)
                {
                    num6 = 1.0 + num6 * -1.0;
                }
                if (num6 <= 0.0)
                {
                    num6 = 0.001;
                }
                else if (num6 >= 1.0)
                {
                    num6 = 0.999;
                }
                double textureT;
                if (bool_1)
                {
                    textureT = 0.0;
                }
                else
                {
                    textureT = 1.0;
                }
                double m = 0.0;
                encode3DProperties.PackTexture2D(num6, textureT, out m);
                point.M = m;
                pointCollection.AddPoint(point, ref value, ref value);
                IClone clone  = point as IClone;
                IPoint point2 = clone.Clone() as IPoint;
                point2.Z = double_4;
                if (bool_1)
                {
                    textureT = 1.0;
                }
                else
                {
                    textureT = 0.0;
                }
                m = 0.0;
                encode3DProperties.PackTexture2D(num6, textureT, out m);
                point2.M = m;
                pointCollection.AddPoint(point2, ref value, ref value);
            }
            IGeometry2 inGeometry = pointCollection as IGeometry2;

            geometryCollection.AddGeometry(inGeometry, ref value, ref value);
            IZAware iZAware = multiPatch as IZAware;

            iZAware.ZAware = true;
            IMAware iMAware = multiPatch as IMAware;

            iMAware.MAware = true;
            return(multiPatch);
        }