コード例 #1
0
        //public static VertexAttribute[] vertAttribs; //convert to cache type


        public MeshRenderer(IAsset meshToRender)
        {
            mesh = (Mesh <IndexType>)meshToRender;
            var type = mesh.Vertices[0].GetType();

            stride = Marshal.SizeOf(type);

            if (!RegisterAsAttribute.registeredVertexFormats.ContainsKey(type))
            {
                RegisterAsAttribute.ParseVertexFormat(type);
            }

            Allocate();
        }
コード例 #2
0
        public override IAsset Import(string pathToFile)
        {
            var format = Path.GetExtension(pathToFile);
            //if (!SupportedFileFormatsAttribute.supportedFileFormats.Contains (format))
            //throw new NotSupportedException (format+" format is not supported");
            var vertexType = vertex().GetType();
            var asset      = new AssimpContext();

            var scene = asset.ImportFile(pathToFile, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessSteps.FlipUVs | PostProcessSteps.Triangulate | PostProcessSteps.MakeLeftHanded | PostProcessSteps.GenerateSmoothNormals | PostProcessSteps.FixInFacingNormals);

            var internalMesh = new Mesh <int>();

            internalMesh.FullPath = pathToFile;
            if (!RegisterAsAttribute.registeredVertexFormats.ContainsKey(vertexType))
            {
                RegisterAsAttribute.ParseVertexFormat(vertexType);
            }
            foreach (var mesh in scene.Meshes)
            {
                //Console.WriteLine ("indices : "+ mesh.GetUnsignedIndices());
                //mesh.MaterialIndex
                //internalMesh.Indices=indexType==typeof(int) ? new int[mesh.VertexCount*3] : new short[mesh.VertexCount*3];
                if (mesh.HasBones)
                {
                    SkeletonPipeline.singleton.scene = scene;
                    AssetsView.tree.AddNode(() => SkeletonPipeline.singleton.Import(""));
                }
                internalMesh.Indices = mesh.GetIndices();              //(ushort[])(object)
                //mesh.has
                var min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                var max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
                internalMesh.Vertices = new IVertex[mesh.VertexCount];

                for (int i = 0; i < mesh.VertexCount; i++)
                {
                    internalMesh.Vertices [i] = vertex();
                    var tmpVec = new Vector3(mesh.Vertices [i].X, mesh.Vertices [i].Y, mesh.Vertices [i].Z);
                    //Console.WriteLine ((maxtmpVec));
                    min = Vector3.ComponentMin(min, tmpVec);
                    max = Vector3.ComponentMax(max, tmpVec);
                    if (mesh.HasVertices)
                    {
                        FillVertexAttrib(vertexType, VertexAttribute.POSITION, ref internalMesh.Vertices[i], new Vector3(mesh.Vertices[i].X, mesh.Vertices[i].Y, mesh.Vertices[i].Z));
                    }
                    if (mesh.HasVertexColors(0) && RegisterAsAttribute.registeredVertexFormats[vertexType].ContainsKey(VertexAttribute.COLOR))
                    {
                        //baseVertData.Color.r = mesh.VertexColorChannels [0] [i].R;
                        //baseVertData.Color.g = mesh.VertexColorChannels [0] [i].G;
                        //baseVertData.Color.b = mesh.VertexColorChannels [0] [i].B;
                        //baseVertData.Color.a = mesh.VertexColorChannels [0] [i].A;
                    }
                    if (mesh.HasTextureCoords(0))
                    {
                        FillVertexAttrib(vertexType, VertexAttribute.UV, ref internalMesh.Vertices[i], new Vector2(mesh.TextureCoordinateChannels [0] [i].X, mesh.TextureCoordinateChannels [0] [i].Y));                      //was 1-texcoord.y
                    }
                    if (mesh.HasNormals)
                    {
                        FillVertexAttrib(vertexType, VertexAttribute.NORMAL, ref internalMesh.Vertices [i], new Vector3(mesh.Normals [i].X, mesh.Normals [i].Y, mesh.Normals [i].Z));
                    }
                }
                bounds = new BoundingBox(min, max);
                internalMesh.UsageHint = UsageHint.DynamicDraw;
            }
            internalMesh.bounds = bounds;
            return(convert?.Invoke(internalMesh) ?? internalMesh);
        }
コード例 #3
0
 public void BindVertexAttrib(int stride, RegisterAsAttribute attrib)
 {
     GL.EnableVertexAttribArray(attrib.shaderLocation);
     GL.VertexAttribPointer(attrib.shaderLocation, attrib.Dimension, (VertexAttribPointerType)attrib.type, false, stride, attrib.offset);
 }