當前位置: 首頁>>代碼示例>>C#>>正文


C# TgcMesh.createBoundingBox方法代碼示例

本文整理匯總了C#中TgcViewer.Utils.TgcSceneLoader.TgcMesh.createBoundingBox方法的典型用法代碼示例。如果您正苦於以下問題:C# TgcMesh.createBoundingBox方法的具體用法?C# TgcMesh.createBoundingBox怎麽用?C# TgcMesh.createBoundingBox使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TgcViewer.Utils.TgcSceneLoader.TgcMesh的用法示例。


在下文中一共展示了TgcMesh.createBoundingBox方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: updateValues

        /// <summary>
        /// Tomar los valores configurados y crear el SkyBox
        /// </summary>
        public void updateValues()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear cada cara
            for (int i = 0; i < faces.Length; i++)
            {
                //Crear mesh de D3D
                Mesh m = new Mesh(2, 4, MeshFlags.Managed, TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);
                SkyFaces skyFace = (SkyFaces)i;

                // Cargo los vértices
                using (VertexBuffer vb = m.VertexBuffer)
                {
                    GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                    int colorRgb = this.color.ToArgb();
                    cargarVertices(skyFace, data, colorRgb);
                    vb.Unlock();
                }

                // Cargo los índices
                using (IndexBuffer ib = m.IndexBuffer)
                {
                    short[] ibArray = new short[6];
                    cargarIndices(ibArray);
                    ib.SetData(ibArray, 0, LockFlags.None);
                }

                //Crear TgcMesh
                string faceName = Enum.GetName(typeof(SkyFaces), skyFace);
                TgcMesh faceMesh = new TgcMesh(m, "SkyBox-" + faceName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
                faceMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
                faceMesh.createBoundingBox();
                faceMesh.Enabled = true;

                //textura
                TgcTexture texture = TgcTexture.createTexture(d3dDevice, faceTextures[i]);
                faceMesh.DiffuseMaps = new TgcTexture[] { texture };

                faceMesh.AutoTransformEnable = false;
                faces[i] = faceMesh;
                matrices[i] = faceMesh.Transform;
            }
        }
開發者ID:SantiagoFoster,項目名稱:AlumnoEjemplos,代碼行數:47,代碼來源:CustomSkyBox.cs

示例2: toMesh

        /// <summary>
        /// Convierte el TgcSphere en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Obtener matriz para transformar vertices
            if (autoTransformEnable)
            {
                this.transform = Matrix.Scaling(radius, radius, radius) * Matrix.Scaling(Scale) * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation);
            }

            //Crear mesh con DiffuseMap
            if (texture != null)
            {
                //Crear Mesh
                Mesh d3dMesh = new Mesh(indices.Count / 3, indices.Count, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);

                //Cargar VertexBuffer
                using (VertexBuffer vb = d3dMesh.VertexBuffer)
                {
                    GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                    for (int j = 0; j < indices.Count; j++)
                    {
                        TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex v = new TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex();
                        Vertex.PositionColoredTexturedNormal vSphere = vertices[indices[j]];

                        //vertices
                        v.Position = Vector3.TransformCoordinate(vSphere.getPosition(), this.transform);

                        //normals
                        v.Normal = vSphere.getNormal();

                        //texture coordinates diffuseMap
                        v.Tu = vSphere.Tu;
                        v.Tv = vSphere.Tv;

                        //color
                        v.Color = vSphere.Color;

                        data.Write(v);
                    }
                    vb.Unlock();
                }

                //Cargar IndexBuffer en forma plana
                using (IndexBuffer ib = d3dMesh.IndexBuffer)
                {
                    short[] vIndices = new short[indices.Count];
                    for (int j = 0; j < vIndices.Length; j++)
                    {
                        vIndices[j] = (short)j;
                    }
                    ib.SetData(vIndices, 0, LockFlags.None);
                }

                //Calcular normales
                //d3dMesh.ComputeNormals();

                //Malla de TGC
                TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
                tgcMesh.DiffuseMaps = new TgcTexture[] { texture.clone() };
                tgcMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
                tgcMesh.createBoundingBox();
                tgcMesh.Enabled = true;
                return tgcMesh;
            }

            //Crear mesh con solo color
            else
            {
                //Crear Mesh
                Mesh d3dMesh = new Mesh(indices.Count / 3, indices.Count, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.VertexColorVertexElements, d3dDevice);

                //Cargar VertexBuffer
                using (VertexBuffer vb = d3dMesh.VertexBuffer)
                {
                    GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                    for (int j = 0; j < indices.Count; j++)
                    {
                        TgcSceneLoader.TgcSceneLoader.VertexColorVertex v = new TgcSceneLoader.TgcSceneLoader.VertexColorVertex();
                        Vertex.PositionColoredTexturedNormal vSphere = vertices[indices[j]];

                        //vertices
                        v.Position = Vector3.TransformCoordinate(vSphere.getPosition(), this.transform);

                        //normals
                        v.Normal = vSphere.getNormal();

                        //color
                        v.Color = vSphere.Color;

                        data.Write(v);
                    }
                    vb.Unlock();
                }

                //Cargar IndexBuffer en forma plana
//.........這裏部分代碼省略.........
開發者ID:aniPerezG,項目名稱:barbalpha,代碼行數:101,代碼來源:TgcSphere.cs

示例3: toMesh

        /// <summary>
        /// Convierte la pared en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear Mesh
            Mesh d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);

            //Cargar VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                Vector3 ceroNormal = new Vector3(0, 0, 0);
                int whiteColor = Color.White.ToArgb();
                for (int j = 0; j < vertices.Length; j++)
                {
                    TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex v = new TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex();
                    CustomVertex.PositionTextured vWall = vertices[j];

                    //vertices
                    v.Position = vWall.Position;

                    //normals
                    v.Normal = ceroNormal;

                    //texture coordinates diffuseMap
                    v.Tu = vWall.Tu;
                    v.Tv = vWall.Tv;

                    //color
                    v.Color = whiteColor;

                    data.Write(v);
                }
                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (IndexBuffer ib = d3dMesh.IndexBuffer)
            {
                short[] indices = new short[vertices.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Calcular normales
            d3dMesh.ComputeNormals();

            //Malla de TGC
            TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
            tgcMesh.DiffuseMaps = new TgcTexture[] { texture.clone() };
            tgcMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return tgcMesh;
        }
開發者ID:JesusHerrera,項目名稱:tgc-viewer,代碼行數:62,代碼來源:TgcPlaneWall.cs

示例4: toMesh

        /// <summary>
        /// Convierte el terreno en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Obtener matriz para transformar vertices
            if (autoTransformEnable)
            {
                this.transform = Matrix.Scaling(scale) * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation);
            }

            //Crear Mesh con DiffuseMap
            Mesh d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);

            //Cargar VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                for (int j = 0; j < vertices.Length; j++)
                {
                    TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex v = new TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex();
                    CustomVertex.PositionTextured vLand = vertices[j];

                    //vertices
                    v.Position = Vector3.TransformCoordinate(vLand.Position, this.transform);

                    //normals
                    v.Normal = Vector3.Empty;

                    //texture coordinates diffuseMap
                    v.Tu = vLand.Tu;
                    v.Tv = vLand.Tv;

                    data.Write(v);
                }
                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (IndexBuffer ib = d3dMesh.IndexBuffer)
            {
                short[] indices = new short[vertices.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Calcular normales
            d3dMesh.ComputeNormals();

            //Malla de TGC
            TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
            tgcMesh.DiffuseMaps = new TgcTexture[] { texture };
            tgcMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return tgcMesh;
        }
開發者ID:JesusHerrera,項目名稱:tgc-viewer,代碼行數:63,代碼來源:TgcEditableLand.cs

示例5: toMesh

        /// <summary>
        /// Convierte el Triángulo en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear Mesh con solo color
            Mesh d3dMesh = new Mesh(1, 3, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.VertexColorVertexElements, d3dDevice);

            //Calcular normal: left-handed
            Vector3 normal = computeNormal();
            int ci = color.ToArgb();

            //Cargar VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                TgcSceneLoader.TgcSceneLoader.VertexColorVertex v;

                //a
                v = new TgcSceneLoader.TgcSceneLoader.VertexColorVertex();
                v.Position = a;
                v.Normal = normal;
                v.Color = ci;
                data.Write(v);

                //b
                v = new TgcSceneLoader.TgcSceneLoader.VertexColorVertex();
                v.Position = b;
                v.Normal = normal;
                v.Color = ci;
                data.Write(v);

                //c
                v = new TgcSceneLoader.TgcSceneLoader.VertexColorVertex();
                v.Position = c;
                v.Normal = normal;
                v.Color = ci;
                data.Write(v);

                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (IndexBuffer ib = d3dMesh.IndexBuffer)
            {
                short[] indices = new short[3];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Malla de TGC
            TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.VERTEX_COLOR);
            tgcMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return tgcMesh;
        }
開發者ID:JesusHerrera,項目名稱:tgc-viewer,代碼行數:63,代碼來源:TgcTriangle.cs

示例6: mergeTwoMeshes


//.........這裏部分代碼省略.........
                int tIdx = 0;
                foreach (TgcTexture t in mesh1.DiffuseMaps)
                {
                    textures[tIdx++] = t.clone();
                }
                //Texturas del mesh2
                foreach (TgcTexture t in mesh2.DiffuseMaps)
                {
                    textures[tIdx++] = t.clone();
                }

                //Cargar el AttributeBuffer con la suma de ambos mesh
                int attIdx = 0;
                int textureId = 0;
                int[] attributeBuffer = mesh.LockAttributeBufferArray(LockFlags.None);

                //AttributeBuffer del mesh 1
                if (mesh1.DiffuseMaps.Length > 1)
                {
                    //Copiar el AttributeBuffer del mesh1 tal cual al mesh unificado
                    int[] attributeBuffer1 = mesh1.D3dMesh.LockAttributeBufferArray(LockFlags.ReadOnly);
                    Array.Copy(attributeBuffer1, attributeBuffer, attributeBuffer1.Length);
                    mesh1.D3dMesh.UnlockAttributeBuffer(attributeBuffer1);
                }
                else
                {
                    //Hay una sola textura, llenar el AttributeBuffer para que apunte solo a esa textura
                    for (int i = 0; i < mesh1.NumberTriangles; i++)
                    {
                        attributeBuffer[i] = textureId;
                    }
                }
                attIdx += mesh1.NumberTriangles;
                textureId += mesh1.DiffuseMaps.Length;

                //AttributeBuffer del mesh 2
                if (mesh2.DiffuseMaps.Length > 1)
                {
                    //Copiar el AttributeBuffer del mesh2 al mesh unificado pero sumando el offset de texturas del primero
                    int[] attributeBuffer2 = mesh2.D3dMesh.LockAttributeBufferArray(LockFlags.ReadOnly);
                    int[] attributeBuffer2Offset = new int[attributeBuffer2.Length];
                    for (int i = 0; i < attributeBuffer2.Length; i++)
                    {
                        attributeBuffer2Offset[i] = attributeBuffer2[i] + textureId;
                    }
                    mesh2.D3dMesh.UnlockAttributeBuffer(attributeBuffer2);
                    Array.Copy(attributeBuffer2Offset, 0, attributeBuffer, attIdx, attributeBuffer2Offset.Length);
                    attributeBuffer2Offset = null;
                }
                else
                {
                    //Hay una sola textura, llenar el AttributeBuffer para que apunte solo a esa textura
                    for (int i = 0; i < mesh2.NumberTriangles; i++)
                    {
                        attributeBuffer[attIdx++] = textureId;
                    }
                    textureId++;
                }

                mesh.UnlockAttributeBuffer(attributeBuffer);
            }

            //Crear mesh de TGC
            TgcMesh tgcMesh = new TgcMesh(mesh, mesh1.Name, mesh1.RenderType);
            tgcMesh.Layer = mesh1.Layer;
            tgcMesh.createBoundingBox();
            tgcMesh.Materials = materials;
            tgcMesh.DiffuseMaps = textures;
            tgcMesh.AlphaBlendEnable = mesh1.AlphaBlendEnable;
            tgcMesh.Enabled = mesh1.Enabled;

            //Transformaciones con la identidad (porque ya transformamos los vertices)
            tgcMesh.Position = new Vector3(0, 0, 0);
            tgcMesh.Rotation = new Vector3(0, 0, 0);
            tgcMesh.Scale = new Vector3(1, 1, 1);
            tgcMesh.Transform = Matrix.Identity;
            tgcMesh.AutoTransformEnable = mesh1.AutoTransformEnable;

            //Agregar userProperties de ambos
            if (mesh1.UserProperties != null || mesh2.UserProperties != null)
            {
                tgcMesh.UserProperties = new Dictionary<string, string>();
                if (mesh1.UserProperties != null)
                {
                    foreach (KeyValuePair<string, string> entry in mesh1.UserProperties)
                    {
                        tgcMesh.UserProperties.Add(entry.Key, entry.Value);
                    }
                }
                if (mesh2.UserProperties != null)
                {
                    foreach (KeyValuePair<string, string> entry in mesh2.UserProperties)
                    {
                        tgcMesh.UserProperties.Add(entry.Key, entry.Value);
                    }
                }
            }

            return tgcMesh;
        }
開發者ID:JesusHerrera,項目名稱:tgc-viewer,代碼行數:101,代碼來源:TgcSceneExporter.cs

示例7: CreateTgcMesh

        /// <summary>
        /// Adaptar mesh de DirectX a mesh de TGC
        /// </summary>
        public TgcMesh CreateTgcMesh(BspMap bspMap, Mesh mesh,int surfaceId)
        {
            QSurface surface = bspMap.Data.drawSurfaces[surfaceId];

            TgcTexture lightmap = surface.lightmapNum >= 0 ? lightMaps[surface.lightmapNum] : null;

            var texture = textures[surface.shaderNum];

            //asigno el shader si es que tiene
            bspMap.Data.shaderXSurface[surfaceId] = shaderXTextura[surface.shaderNum];
            if (bspMap.Data.shaderXSurface[surfaceId] != null)
                bspMap.Data.shaderXSurface[surfaceId].BuildFx();

            if (texture == null && bspMap.Data.shaderXSurface[surfaceId] != null)
            {
                foreach (QShaderStage stage in bspMap.Data.shaderXSurface[surfaceId].Stages)
                {
                    if (stage.Textures.Count > 0)
                    {
                        texture = stage.Textures[0];
                        break;
                    }

                }
            }


            //Cargar lightMap
            TgcTexture tgcLightMap = lightmap;
            if (lightmap == null)
                tgcLightMap = emptyLightMap;

            TgcTexture[] meshTextures = new TgcTexture[1];
            if (texture != null)
            {
                meshTextures[0] = texture;
            }
            else
            {
                meshTextures[0] = emptyTexture;
            }

            TgcMesh.MeshRenderType renderType = TgcMesh.MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP;
            
            Material mat = new Material();
            mat.Ambient = Color.White;

            //Crear mesh de TGC
            TgcMesh tgcMesh = new TgcMesh(mesh, "mesh" + surfaceId, renderType);
            tgcMesh.Materials = new Material[] { mat };
            tgcMesh.DiffuseMaps = meshTextures;
            tgcMesh.LightMap = tgcLightMap;
            tgcMesh.Enabled = true;
            tgcMesh.createBoundingBox();

            return tgcMesh;
        }
開發者ID:aniPerezG,項目名稱:barbalpha,代碼行數:60,代碼來源:BspLoader.cs

示例8: applyMeshTransformToVertices

        /// <summary>
        /// Transformar fisicamente los vertices del mesh segun su transformacion actual
        /// </summary>
        private void applyMeshTransformToVertices(TgcMesh m)
        {
            //Transformacion actual
            Matrix transform = Matrix.Scaling(m.Scale)
                    * Matrix.RotationYawPitchRoll(m.Rotation.Y, m.Rotation.X, m.Rotation.Z)
                    * Matrix.Translation(m.Position);

            switch (m.RenderType)
            {
                case TgcMesh.MeshRenderType.VERTEX_COLOR:
                    TgcSceneLoader.VertexColorVertex[] verts1 = (TgcSceneLoader.VertexColorVertex[])m.D3dMesh.LockVertexBuffer(
                        typeof(TgcSceneLoader.VertexColorVertex), LockFlags.ReadOnly, m.D3dMesh.NumberVertices);
                    for (int i = 0; i < verts1.Length; i++)
                    {
                        verts1[i].Position = TgcVectorUtils.transform(verts1[i].Position, transform);
                    }
                    m.D3dMesh.SetVertexBufferData(verts1, LockFlags.None);
                    m.D3dMesh.UnlockVertexBuffer();
                    break;

                case TgcMesh.MeshRenderType.DIFFUSE_MAP:
                    TgcSceneLoader.DiffuseMapVertex[] verts2 = (TgcSceneLoader.DiffuseMapVertex[])m.D3dMesh.LockVertexBuffer(
                        typeof(TgcSceneLoader.DiffuseMapVertex), LockFlags.ReadOnly, m.D3dMesh.NumberVertices);
                    for (int i = 0; i < verts2.Length; i++)
                    {
                        verts2[i].Position = TgcVectorUtils.transform(verts2[i].Position, transform);
                    }
                    m.D3dMesh.SetVertexBufferData(verts2, LockFlags.None);
                    m.D3dMesh.UnlockVertexBuffer();
                    break;

                case TgcMesh.MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP:
                    TgcSceneLoader.DiffuseMapAndLightmapVertex[] verts3 = (TgcSceneLoader.DiffuseMapAndLightmapVertex[])m.D3dMesh.LockVertexBuffer(
                        typeof(TgcSceneLoader.DiffuseMapAndLightmapVertex), LockFlags.ReadOnly, m.D3dMesh.NumberVertices);
                    for (int i = 0; i < verts3.Length; i++)
                    {
                        verts3[i].Position = TgcVectorUtils.transform(verts3[i].Position, transform);
                    }
                    m.D3dMesh.SetVertexBufferData(verts3, LockFlags.None);
                    m.D3dMesh.UnlockVertexBuffer();
                    break;
            }

            //Quitar movimientos del mesh
            m.Position = new Vector3(0, 0, 0);
            m.Scale = new Vector3(1, 1, 1);
            m.Rotation = new Vector3(0, 0, 0);
            m.Transform = Matrix.Identity;
            m.AutoTransformEnable = true;

            //Calcular nuevo bounding box
            m.createBoundingBox();
        }
開發者ID:aniPerezG,項目名稱:barbalpha,代碼行數:56,代碼來源:MeshPrimitive.cs


注:本文中的TgcViewer.Utils.TgcSceneLoader.TgcMesh.createBoundingBox方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。