当前位置: 首页>>代码示例>>C#>>正文


C# Mesh.LockAttributeBufferArray方法代码示例

本文整理汇总了C#中Mesh.LockAttributeBufferArray方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.LockAttributeBufferArray方法的具体用法?C# Mesh.LockAttributeBufferArray怎么用?C# Mesh.LockAttributeBufferArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mesh的用法示例。


在下文中一共展示了Mesh.LockAttributeBufferArray方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateMesh

        private Mesh CreateMesh(aiMesh aiMesh, out Vector3 min, out Vector3 max)
        {
            var numFaces = (int) aiMesh.mNumFaces;
            var numVertices = (int) aiMesh.mNumVertices;

            var dxMesh = new Mesh(numFaces, numVertices, MeshFlags.Managed | MeshFlags.Use32Bit,
                CustomVertex.PositionNormalTextured.Format, device);

            var aiPositions = aiMesh.mVertices;
            var aiNormals = aiMesh.mNormals;
            var aiTextureCoordsAll = aiMesh.mTextureCoords;
            var aiTextureCoords = (aiTextureCoordsAll!=null) ? aiTextureCoordsAll[0] : null;
            var dxVertices = new CustomVertex.PositionNormalTextured[numVertices];
            for (int i = 0; i < numVertices; ++i) {
                dxVertices[i].Position = aiPositions[i].ToVector3();
                if (aiNormals != null) {
                    dxVertices[i].Normal = aiNormals[i].ToVector3();
                }
                if (aiTextureCoords != null) {
                    var uv = aiTextureCoords[i];
                    dxVertices[i].Tu = uv.x;
                    dxVertices[i].Tv = uv.y;
                }
            }
            dxMesh.VertexBuffer.SetData(dxVertices, 0, LockFlags.None);

            var aiFaces = aiMesh.mFaces;
            var dxIndices = new uint[numFaces * 3];
            for (int i = 0; i < numFaces; ++i) {
                var aiFace = aiFaces[i];
                var aiIndices = aiFace.mIndices;
                for (int j = 0; j < 3; ++j) {
                    dxIndices[i * 3 + j] = aiIndices[j];
                }
            }
            dxMesh.IndexBuffer.SetData(dxIndices, 0, LockFlags.None);

            var dxAttributes = dxMesh.LockAttributeBufferArray(LockFlags.None);
            // TODO: Set face material index for attributes
            dxMesh.UnlockAttributeBuffer(dxAttributes);

            var adjacency = new int[numFaces * 3];
            dxMesh.GenerateAdjacency(0.0f, adjacency);
            dxMesh.OptimizeInPlace(MeshFlags.OptimizeAttributeSort, adjacency);

            Geometry.ComputeBoundingBox(dxVertices, CustomVertex.PositionNormalTextured.StrideSize, out min, out max);

            return dxMesh;
        }
开发者ID:henrikno,项目名称:assimp,代码行数:49,代码来源:AssimpView.cs

示例2: fromTgcMesh


//.........这里部分代码省略.........

            //Crear nuevo VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                //Iterar sobre triangulos
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                for (int i = 0; i < triCount; i++)
                {
                    //Vertices originales
                    TgcSceneLoader.DiffuseMapVertex vOrig1 = origVertexBuffer[i * 3];
                    TgcSceneLoader.DiffuseMapVertex vOrig2 = origVertexBuffer[i * 3 + 1];
                    TgcSceneLoader.DiffuseMapVertex vOrig3 = origVertexBuffer[i * 3 + 2];

                    //Nuevo vertice 1
                    BumpMappingVertex v1 = new BumpMappingVertex();
                    v1.Position = vOrig1.Position;
                    v1.Color = vOrig1.Color;
                    v1.Tu = vOrig1.Tu;
                    v1.Tv = vOrig1.Tv;
                    v1.Normal = normals[i * 3];

                    //Nuevo vertice 2
                    BumpMappingVertex v2 = new BumpMappingVertex();
                    v2.Position = vOrig2.Position;
                    v2.Color = vOrig2.Color;
                    v2.Tu = vOrig2.Tu;
                    v2.Tv = vOrig2.Tv;
                    v2.Normal = normals[i * 3 + 1];

                    //Nuevo vertice 3
                    BumpMappingVertex v3 = new BumpMappingVertex();
                    v3.Position = vOrig3.Position;
                    v3.Color = vOrig3.Color;
                    v3.Tu = vOrig3.Tu;
                    v3.Tv = vOrig3.Tv;
                    v3.Normal = normals[i * 3 + 2];

                    //Calcular tangente y binormal para todo el triangulo y cargarlas en cada vertice
                    Vector3 tangent;
                    Vector3 binormal;
                    TgcMeshBumpMapping.computeTangentBinormal(v1, v2, v3, out tangent, out binormal);
                    v1.Tangent = tangent;
                    v1.Binormal = binormal;
                    v2.Tangent = tangent;
                    v2.Binormal = binormal;
                    v3.Tangent = tangent;
                    v3.Binormal = binormal;

                    //Cargar VertexBuffer
                    data.Write(v1);
                    data.Write(v2);
                    data.Write(v3);
                }

                vb.Unlock();
            }

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

            //Clonar texturas y materials
            TgcTexture[] diffuseMaps = new TgcTexture[mesh.DiffuseMaps.Length];
            Material[] materials = new Material[mesh.Materials.Length];
            for (int i = 0; i < mesh.DiffuseMaps.Length; i++)
            {
                diffuseMaps[i] = mesh.DiffuseMaps[i].clone();
                materials[i] = TgcD3dDevice.DEFAULT_MATERIAL;
            }

            //Cargar attributeBuffer
            if (diffuseMaps.Length > 1)
            {
                int[] origAttributeBuffer = mesh.D3dMesh.LockAttributeBufferArray(LockFlags.None);
                int[] newAttributeBuffer = d3dMesh.LockAttributeBufferArray(LockFlags.None);
                Array.Copy(origAttributeBuffer, newAttributeBuffer, origAttributeBuffer.Length);
                mesh.D3dMesh.UnlockAttributeBuffer();
                d3dMesh.UnlockAttributeBuffer(newAttributeBuffer);
            }

            //Crear mesh de BumpMapping Mesh
            TgcMeshBumpMapping bumpMesh = new TgcMeshBumpMapping(d3dMesh, mesh.Name, mesh.RenderType);
            bumpMesh.diffuseMaps = diffuseMaps;
            bumpMesh.materials = materials;
            bumpMesh.normalMaps = normalMaps;
            bumpMesh.layer = mesh.Layer;
            bumpMesh.alphaBlendEnable = mesh.AlphaBlendEnable;
            bumpMesh.UserProperties = mesh.UserProperties;
            bumpMesh.boundingBox = mesh.BoundingBox.clone();
            bumpMesh.enabled = true;

            return bumpMesh;
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:101,代码来源:TgcMeshBumpMapping.cs

示例3: d3d_DxRestore

		/// <summary>
		/// Restore the mesh when the DirectX device is restored
		/// </summary>
		void d3d_DxRestore(Direct3d d3d, Device dx)
		{
			// If the direct3d device wasn't lost in the first place, don't restore it.
			// This happens the first timeMs around.
			if (mMesh != null)
				return;

			// Restore mesh			
			mMesh = new Mesh(mNumFaces, mNumVertices, mFlags, mVertexFormat, dx);
			Debug.Assert(mMesh.NumberBytesPerVertex == mNumBytesPerVertex);

			// Copy pathIndex buffer
			GraphicsStream stream = mMesh.LockIndexBuffer(LockFlags.Discard);
			stream.Write(mIndexBufferCopy);
			mMesh.UnlockIndexBuffer();
			
			// Copy vertex buffer
			stream = mMesh.LockVertexBuffer(LockFlags.Discard);
			stream.Write(mVertexBufferCopy);
			mMesh.UnlockVertexBuffer();

			// Copy attribute buffer
			int[] attributeBuffer = mMesh.LockAttributeBufferArray(LockFlags.Discard);
			mAttributeBufferCopy.CopyTo(attributeBuffer, 0);
			mMesh.UnlockAttributeBuffer(attributeBuffer);

			mIndexBufferCopy = null;
			mVertexBufferCopy = null;
			mAttributeBufferCopy = null;
		}
开发者ID:kasertim,项目名称:sentience,代码行数:33,代码来源:Direct3d.cs

示例4: crearMeshDiffuseMap


//.........这里部分代码省略.........
                    //normal
                    if (meshData.verticesNormals != null)
                    {
                        v.Normal = new Vector3(
                            meshData.verticesNormals[coordIdx],
                            meshData.verticesNormals[coordIdx + 1],
                            meshData.verticesNormals[coordIdx + 2]
                            );
                    }
                    else
                    {
                        v.Normal = new Vector3(0, 0, 0);
                    }

                    //tangent
                    if (meshData.verticesTangents != null)
                    {
                        v.Tangent = new Vector3(
                            meshData.verticesTangents[coordIdx],
                            meshData.verticesTangents[coordIdx + 1],
                            meshData.verticesTangents[coordIdx + 2]
                            );
                    }
                    else
                    {
                        v.Tangent = new Vector3(0, 0, 0);
                    }

                    //binormal
                    if (meshData.verticesBinormals != null)
                    {
                        v.Binormal = new Vector3(
                            meshData.verticesBinormals[coordIdx],
                            meshData.verticesBinormals[coordIdx + 1],
                            meshData.verticesBinormals[coordIdx + 2]
                            );
                    }
                    else
                    {
                        v.Binormal = new Vector3(0, 0, 0);
                    }
                    


                    //BlendWeights y BlendIndices
                    TgcSkeletalVertexWeight vWeight = verticesWeights[meshData.coordinatesIndices[j]];
                    vWeight.createVector4WeightsAndIndices(out v.BlendWeights, out v.BlendIndices);



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

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

            //Configurar Material y Textura para un solo SubSet
            TgcSkeletalLoaderMaterialAux matAux = materialsArray[meshData.materialId];
            Material[] meshMaterials;
            TgcTexture[] meshTextures;
            if (matAux.subMaterials == null)
            {
                meshMaterials = new Material[] { matAux.materialId };
                meshTextures = new TgcTexture[] { matAux.texture };
            }

            //Configurar Material y Textura para varios SubSet
            else
            {
                //Cargar attributeBuffer con los id de las texturas de cada triángulo
                int[] attributeBuffer = mesh.LockAttributeBufferArray(LockFlags.None);
                Array.Copy(meshData.materialsIds, attributeBuffer, attributeBuffer.Length);
                mesh.UnlockAttributeBuffer(attributeBuffer);

                //Cargar array de Materials y Texturas
                meshMaterials = new Material[matAux.subMaterials.Length];
                meshTextures = new TgcTexture[matAux.subMaterials.Length];
                for (int m = 0; m < matAux.subMaterials.Length; m++)
                {
                    meshMaterials[m] = matAux.subMaterials[m].materialId;
                    meshTextures[m] = matAux.subMaterials[m].texture;
                }
            }

            //Crear mesh de TGC
            TgcSkeletalMesh tgcMesh = meshFactory.createNewMesh(mesh, meshData.name, TgcSkeletalMesh.MeshRenderType.DIFFUSE_MAP, bones);
            tgcMesh.Materials = meshMaterials;
            tgcMesh.DiffuseMaps = meshTextures;
            return tgcMesh;
        }
开发者ID:aniPerezG,项目名称:barbalpha,代码行数:101,代码来源:TgcSkeletalLoader.cs

示例5: mergeTwoMeshes


//.........这里部分代码省略.........
            //Cargar texturas y attributeBuffer
            TgcTexture[] textures = null;
            Material[] materials = null;
            if (mesh1.RenderType == TgcMesh.MeshRenderType.DIFFUSE_MAP)
            {
                //Cargar materials
                materials = new Material[mesh1.DiffuseMaps.Length + mesh2.DiffuseMaps.Length];
                int mIdx = 0;
                foreach (Material m in mesh1.Materials)
                {
                    materials[mIdx++] = m;
                }
                foreach (Material m in mesh2.Materials)
                {
                    materials[mIdx++] = m;
                }

                //Texturas del mesh1
                textures = new TgcTexture[mesh1.DiffuseMaps.Length + mesh2.DiffuseMaps.Length];
                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);
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:67,代码来源:TgcSceneExporter.cs

示例6: crearMeshDiffuseMap

        /// <summary>
        /// Crea un mesh con uno o varios DiffuseMap
        /// </summary>
        /// <returns></returns>
        private TgcKeyFrameMesh crearMeshDiffuseMap(TgcKeyFrameLoaderMaterialAux[] materialsArray, TgcKeyFrameMeshData meshData)
        {
            //Crear Mesh
            Mesh mesh = new Mesh(meshData.coordinatesIndices.Length / 3, meshData.coordinatesIndices.Length, MeshFlags.Managed, DiffuseMapVertexElements, device);

            //Cargar VertexBuffer
            using (VertexBuffer vb = mesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                for (int j = 0; j < meshData.coordinatesIndices.Length; j++)
                {
                    DiffuseMapVertex v = new DiffuseMapVertex();

                    //vertices
                    int coordIdx = meshData.coordinatesIndices[j] * 3;
                    v.Position = new Vector3(
                        meshData.verticesCoordinates[coordIdx],
                        meshData.verticesCoordinates[coordIdx + 1],
                        meshData.verticesCoordinates[coordIdx + 2]
                        );

                    //texture coordinates diffuseMap
                    int texCoordIdx = meshData.texCoordinatesIndices[j] * 2;
                    v.Tu = meshData.textureCoordinates[texCoordIdx];
                    v.Tv = meshData.textureCoordinates[texCoordIdx + 1];

                    //color
                    int colorIdx = meshData.colorIndices[j];
                    v.Color = meshData.verticesColors[colorIdx];

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

            //Cargar IndexBuffer
            using (IndexBuffer ib = mesh.IndexBuffer)
            {
                short[] indices = new short[meshData.coordinatesIndices.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Configurar Material y Textura para un solo SubSet
            TgcKeyFrameLoaderMaterialAux matAux = materialsArray[meshData.materialId];
            Material[] meshMaterials;
            TgcTexture[] meshTextures;
            if (matAux.subMaterials == null)
            {
                meshMaterials = new Material[] { matAux.materialId };
                meshTextures = new TgcTexture[] { matAux.texture };
            }

            //Configurar Material y Textura para varios SubSet
            else
            {
                //Cargar attributeBuffer con los id de las texturas de cada triángulo
                int[] attributeBuffer = mesh.LockAttributeBufferArray(LockFlags.None);
                Array.Copy(meshData.materialsIds, attributeBuffer, attributeBuffer.Length);
                mesh.UnlockAttributeBuffer(attributeBuffer);

                //Cargar array de Materials y Texturas
                meshMaterials = new Material[matAux.subMaterials.Length];
                meshTextures = new TgcTexture[matAux.subMaterials.Length];
                for (int m = 0; m < matAux.subMaterials.Length; m++)
                {
                    meshMaterials[m] = matAux.subMaterials[m].materialId;
                    meshTextures[m] = matAux.subMaterials[m].texture;
                }
            }

            //Cargar datos que originales que tienen que mantenerse
            TgcKeyFrameMesh.OriginalData originalData = new TgcKeyFrameMesh.OriginalData();
            originalData.coordinatesIndices = meshData.coordinatesIndices;
            originalData.colorIndices = meshData.colorIndices;
            originalData.verticesColors = meshData.verticesColors;
            originalData.texCoordinatesIndices = meshData.texCoordinatesIndices;
            originalData.textureCoordinates = meshData.textureCoordinates;

            //Crear mesh de TGC
            TgcKeyFrameMesh tgcMesh = new TgcKeyFrameMesh(mesh, meshData.name, TgcKeyFrameMesh.MeshRenderType.DIFFUSE_MAP, originalData);
            tgcMesh.Materials = meshMaterials;
            tgcMesh.DiffuseMaps = meshTextures;
            return tgcMesh;
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:92,代码来源:TgcKeyFrameLoader.cs

示例7: crearMeshDiffuseMapLightmap

        /// <summary>
        /// Crea un mesh con uno o varios DiffuseMap y un Lightmap
        /// </summary>
        /// <returns></returns>
        private TgcMesh crearMeshDiffuseMapLightmap(TgcSceneData sceneData, string mediaPath, TgcSceneLoaderMaterialAux[] materialsArray, TgcMeshData meshData)
        {
            //Crear Mesh
            Mesh mesh = new Mesh(meshData.coordinatesIndices.Length / 3, meshData.coordinatesIndices.Length, MeshFlags.Managed, DiffuseMapAndLightmapVertexElements, device);

            //Cargar vertexBuffer
            using (VertexBuffer vb = mesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                for (int j = 0; j < meshData.coordinatesIndices.Length; j++)
                {
                    DiffuseMapAndLightmapVertex v = new DiffuseMapAndLightmapVertex();

                    //vertices
                    int coordIdx = meshData.coordinatesIndices[j] * 3;
                    v.Position = new Vector3(
                        meshData.verticesCoordinates[coordIdx],
                        meshData.verticesCoordinates[coordIdx + 1],
                        meshData.verticesCoordinates[coordIdx + 2]
                        );

                    //normals
                    //puede haber una normal compartida para cada vertice del mesh
                    if (meshData.verticesNormals.Length == meshData.verticesCoordinates.Length)
                    {
                        v.Normal = new Vector3(
                            meshData.verticesNormals[coordIdx],
                            meshData.verticesNormals[coordIdx + 1],
                            meshData.verticesNormals[coordIdx + 2]
                            );
                    }
                    //o una normal propia por cada vertice de cada triangulo (version mejorada del exporter)
                    else
                    {
                        int normalIdx = j * 3;
                        v.Normal = new Vector3(
                            meshData.verticesNormals[normalIdx],
                            meshData.verticesNormals[normalIdx + 1],
                            meshData.verticesNormals[normalIdx + 2]
                            );
                    }

                    //texture coordinates diffuseMap
                    int texCoordIdx = meshData.texCoordinatesIndices[j] * 2;
                    v.Tu0 = meshData.textureCoordinates[texCoordIdx];
                    v.Tv0 = meshData.textureCoordinates[texCoordIdx + 1];

                    //texture coordinates LightMap
                    int texCoordIdxLM = meshData.texCoordinatesIndicesLightMap[j] * 2;
                    v.Tu1 = meshData.textureCoordinatesLightMap[texCoordIdxLM];
                    v.Tv1 = meshData.textureCoordinatesLightMap[texCoordIdxLM + 1];

                    //color
                    int colorIdx = meshData.colorIndices[j];
                    v.Color = meshData.verticesColors[colorIdx];

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

            }

            //Cargar IndexBuffer
            using (IndexBuffer ib = mesh.IndexBuffer)
            {
                short[] indices = new short[meshData.coordinatesIndices.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Configurar Material y Textura para un solo SubSet
            TgcSceneLoaderMaterialAux matAux = materialsArray[meshData.materialId];
            Material[] meshMaterials;
            TgcTexture[] meshTextures;
            if (matAux.subMaterials == null)
            {
                meshMaterials = new Material[] { matAux.materialId };
                meshTextures = new TgcTexture[] { matAux.texture };
            }

            //Configurar Material y Textura para varios SubSet
            else
            {
                //Cargar attributeBuffer con los id de las texturas de cada triángulo
                int[] attributeBuffer = mesh.LockAttributeBufferArray(LockFlags.None);
                Array.Copy(meshData.materialsIds, attributeBuffer, attributeBuffer.Length);
                mesh.UnlockAttributeBuffer(attributeBuffer);

                //Cargar array de Materials y Texturas
                meshMaterials = new Material[matAux.subMaterials.Length];
                meshTextures = new TgcTexture[matAux.subMaterials.Length];
                for (int m = 0; m < matAux.subMaterials.Length; m++)
                {
//.........这里部分代码省略.........
开发者ID:faloi,项目名称:tegece,代码行数:101,代码来源:TgcSceneLoader.cs

示例8: createMovementGizmo


//.........这里部分代码省略.........
                indices[i * eachILength + 11] = (short)(i * eachVLength + 5);

                indices[i * eachILength + 12] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 13] = (short)(i * eachVLength + 5);
                indices[i * eachILength + 14] = (short)(i * eachVLength + 6);

                indices[i * eachILength + 15] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 16] = (short)(i * eachVLength + 6);
                indices[i * eachILength + 17] = (short)(i * eachVLength + 7);

                indices[i * eachILength + 18] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 19] = (short)(i * eachVLength + 7);
                indices[i * eachILength + 20] = (short)(i * eachVLength + 8);

                indices[i * eachILength + 21] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 22] = (short)(i * eachVLength + 8);
                indices[i * eachILength + 23] = (short)(i * eachVLength + 1);
            }

            for (int i = 3; i < 6; i++)
            {
                // Shaft
                indices[i * eachILength + 0] = (short)((i - 3) * eachVLength + 9);
                indices[i * eachILength + 1] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 2] = (short)((i - 3) * eachVLength + 10);
                indices[i * eachILength + 3] = (short)((i - 3) * eachVLength + 10);
                indices[i * eachILength + 4] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 5] = (short)((i - 3) * eachVLength + 14);

                indices[i * eachILength + 6] = (short)((i - 3) * eachVLength + 10);
                indices[i * eachILength + 7] = (short)((i - 3) * eachVLength + 14);
                indices[i * eachILength + 8] = (short)((i - 3) * eachVLength + 11);
                indices[i * eachILength + 9] = (short)((i - 3) * eachVLength + 11);
                indices[i * eachILength + 10] = (short)((i - 3) * eachVLength + 14);
                indices[i * eachILength + 11] = (short)((i - 3) * eachVLength + 15);

                indices[i * eachILength + 12] = (short)((i - 3) * eachVLength + 11);
                indices[i * eachILength + 13] = (short)((i - 3) * eachVLength + 15);
                indices[i * eachILength + 14] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 15] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 16] = (short)((i - 3) * eachVLength + 15);
                indices[i * eachILength + 17] = (short)((i - 3) * eachVLength + 16);

                indices[i * eachILength + 18] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 19] = (short)((i - 3) * eachVLength + 16);
                indices[i * eachILength + 20] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 21] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 22] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 23] = (short)((i - 3) * eachVLength + 9);
            }

            // Squares
            indices[6 * eachILength + 0] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 1] = (short)(3 * eachVLength + 1);
            indices[6 * eachILength + 2] = (short)(3 * eachVLength + 4);
            indices[6 * eachILength + 3] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 4] = (short)(3 * eachVLength + 2);
            indices[6 * eachILength + 5] = (short)(3 * eachVLength + 4);

            indices[6 * eachILength + 6] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 7] = (short)(3 * eachVLength + 2);
            indices[6 * eachILength + 8] = (short)(3 * eachVLength + 6);
            indices[6 * eachILength + 9] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 10] = (short)(3 * eachVLength + 3);
            indices[6 * eachILength + 11] = (short)(3 * eachVLength + 6);

            indices[6 * eachILength + 12] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 13] = (short)(3 * eachVLength + 3);
            indices[6 * eachILength + 14] = (short)(3 * eachVLength + 5);
            indices[6 * eachILength + 15] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 16] = (short)(3 * eachVLength + 1);
            indices[6 * eachILength + 17] = (short)(3 * eachVLength + 5);

            m.SetIndexBufferData(indices, LockFlags.None);

            #endregion

            int[] attr = m.LockAttributeBufferArray(LockFlags.Discard);
            int step = eachILength / 3; // 1 face = 3 indices
            for (int i = 0; i < step; i++)
            {
                attr[step * 0 + i] = 0;
                attr[step * 1 + i] = 1;
                attr[step * 2 + i] = 2;
                attr[step * 3 + i] = 3;
                attr[step * 4 + i] = 4;
                attr[step * 5 + i] = 5;
            }

            for (int i = step * 6; i < attr.Length; i++)
            {
                attr[i] = 6 + (i - step * 6) / 2;
            }

            m.UnlockAttributeBuffer(attr);
            int[] adj = new int[m.NumberFaces * 3];
            m.GenerateAdjacency(0.001f, adj);
            m.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adj);
            this.gizmo = m;
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:101,代码来源:Gizmo.cs


注:本文中的Mesh.LockAttributeBufferArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。