public static VBOArrayF LoadModel(string modelPath) { AssimpModelLoader loader = new AssimpModelLoader(modelPath); MeshVertexData meshData = loader.GetMeshData(); return(new VBOArrayF(meshData.Verts, meshData.N_Verts, meshData.T_Verts, false)); }
private VertexArrayObject AllocateVaoMemory(string path) { VertexArrayObject vao = null; using (AssimpModelLoader loader = new AssimpModelLoader(path)) { MeshVertexData meshData = loader.GetMeshData(); VertexBufferObjectTwoDimension <float> verticesVBO = new VertexBufferObjectTwoDimension <float>(meshData.Verts, BufferTarget.ArrayBuffer, 0, 3, VertexBufferObjectBase.DataCarryFlag.Invalidate); VertexBufferObjectTwoDimension <float> normalsVBO = new VertexBufferObjectTwoDimension <float>(meshData.N_Verts, BufferTarget.ArrayBuffer, 1, 3, VertexBufferObjectBase.DataCarryFlag.Invalidate); VertexBufferObjectTwoDimension <float> texCoordsVBO = new VertexBufferObjectTwoDimension <float>(meshData.T_Verts, BufferTarget.ArrayBuffer, 2, 2, VertexBufferObjectBase.DataCarryFlag.Invalidate); var transformationVboTuples = PlantUserAttributeBuilder.GetInstacedTransformationBuffer(_plants, INIT_BUFFER_SIZE); var windVBO = PlantUserAttributeBuilder.GetInstancedWindBuffer(_plants, INIT_BUFFER_SIZE); var samplerVBO = PlantUserAttributeBuilder.GetInstanceSamplerBuffer(_plants, INIT_BUFFER_SIZE); vao = new VertexArrayObject(); vao.AddVBO(verticesVBO, normalsVBO, texCoordsVBO, transformationVboTuples.Item1.Item1, transformationVboTuples.Item1.Item2, transformationVboTuples.Item2.Item1, transformationVboTuples.Item2.Item2, windVBO, samplerVBO); vao.BindBuffersToVao(); } return(vao); }
public MeshVertexData GetMeshData() { if (m_meshData == null) { var strategy = GetBoneInfluenceStrategy(m_scene); m_meshData = new MeshVertexData(m_scene, strategy); } return(m_meshData); }
private Skin SendDataToGpu(string modelPath) { Skin resultSkin = null; // Get mesh data using (AssimpModelLoader loader = new AssimpModelLoader(modelPath)) { VertexArrayObject vao = new VertexArrayObject(); MeshVertexData meshData = loader.GetMeshData(); // explicit null assignment if there is no some of mesh data var vertices = meshData.Verts; var normals = meshData.bHasNormals ? meshData.N_Verts : null; var texCoords = meshData.T_Verts; var tangents = meshData.bHasTangentVertices ? meshData.Tangent_Verts : meshData.bHasTextureCoordinates ? VectorMath.AdditionalVertexInfoCreator.CreateTangentVertices(vertices, texCoords) : null; var bitangents = meshData.bHasTangentVertices ? meshData.Bitanget_Verts : meshData.bHasTextureCoordinates ? VectorMath.AdditionalVertexInfoCreator.CreateBitangentVertices(vertices, texCoords) : null; var blendWeights = meshData.bHasAnimation ? meshData.BlendWeights : null; var blendIndices = meshData.bHasAnimation ? meshData.BlendIndices : null; UInt32[] indices = meshData.bHasIndices ? meshData.Indices.ToArray() : null; IndexBufferObject ibo = null; VertexBufferObjectTwoDimension <float> normalsVBO = null, texCoordsVBO = null, tangentsVBO = null, bitangentsVBO = null, blendWeightsVBO = null; VertexBufferObjectTwoDimension <Int32> blendIndicesVBO = null; if (meshData.bHasIndices) { ibo = new IndexBufferObject(indices); } VertexBufferObjectTwoDimension <float> vertexVBO = new VertexBufferObjectTwoDimension <float>(vertices, BufferTarget.ArrayBuffer, 0, 3, VertexBufferObjectBase.DataCarryFlag.Invalidate); if (meshData.bHasNormals) { normalsVBO = new VertexBufferObjectTwoDimension <float>(normals, BufferTarget.ArrayBuffer, 1, 3, VertexBufferObjectBase.DataCarryFlag.Invalidate); } if (meshData.bHasTextureCoordinates) { texCoordsVBO = new VertexBufferObjectTwoDimension <float>(texCoords, BufferTarget.ArrayBuffer, 2, 2, VertexBufferObjectBase.DataCarryFlag.Invalidate); } if (meshData.bHasTangentVertices) { tangentsVBO = new VertexBufferObjectTwoDimension <float>(tangents, BufferTarget.ArrayBuffer, 4, 3, VertexBufferObjectBase.DataCarryFlag.Invalidate); } if (meshData.bHasTangentVertices) { bitangentsVBO = new VertexBufferObjectTwoDimension <float>(bitangents, BufferTarget.ArrayBuffer, 5, 3, VertexBufferObjectBase.DataCarryFlag.Invalidate); } if (meshData.bHasAnimation) { Int32 skeletonWeightsPerVertexCount = (Int32)loader.m_skeletonType; if (skeletonWeightsPerVertexCount > 4) { throw new NotImplementedException("There is no implementation yet for cases when there are more than four weights influencing on vertex."); } Int32 vectorSize = skeletonWeightsPerVertexCount; blendWeightsVBO = new VertexBufferObjectTwoDimension <float>(blendWeights, BufferTarget.ArrayBuffer, 6, vectorSize, VertexBufferObjectBase.DataCarryFlag.Invalidate); blendIndicesVBO = new VertexBufferObjectTwoDimension <int>(blendIndices, BufferTarget.ArrayBuffer, 7, vectorSize, VertexBufferObjectBase.DataCarryFlag.Invalidate); } vao.AddVBO(vertexVBO, normalsVBO, texCoordsVBO, tangentsVBO, bitangentsVBO, blendWeightsVBO, blendIndicesVBO); vao.AddIndexBuffer(ibo); vao.BindBuffersToVao(); if (meshData.bHasAnimation) { ParentBone rootBone = AssimpConverter.Converter.ConvertAssimpBoneToEngineBone(meshData.SkeletonRoot); resultSkin = new AnimatedSkin(vao, rootBone); } else { resultSkin = new Skin(vao); } } return(resultSkin); }