Exemple #1
0
        private static SceneNodeContainer CreateFuseeNode(string name, TransformComponent xform, MaterialComponent mat, Mesh mesh)
        {
            var fuNode = new SceneNodeContainer {
                Name = name
            };

            if (xform != null)
            {
                fuNode.AddComponent(xform);
            }

            if (mat != null)
            {
                fuNode.AddComponent(mat);
            }

            if (mesh != null)
            {
                fuNode.AddComponent(mesh);
            }

            return(fuNode);
        }
Exemple #2
0
        /* TODO: Merge changes from morithfu/FUSEE3D branch: feat_AdvShaderCodeBuilder to FUSEE3D develop branch, to be able to use this function
         * private static LightComponent GetLight(Light light)
         * {
         *  var asLight = light;
         *
         *  var asAmbient = new float3(asLight.ColorAmbient.R, asLight.ColorAmbient.G, asLight.ColorAmbient.B);
         *  var asPosition = new float3(asLight.Position.X, asLight.Position.Y, asLight.Position.Z);
         *  var asConeAngle = asLight.AngleOuterCone;
         *  var asAttenuation = asLight.AttenuationConstant;
         *  var asColor = new float3(asLight.ColorDiffuse.R, asLight.ColorDiffuse.G, asLight.ColorDiffuse.B);
         *  var asConeDirection = new float3(asLight.Direction.X, asLight.Direction.Y, asLight.Direction.Z);
         *  var asLightType = asLight.LightType; // Undefined = 0, Directional = 1, Point = 2, Spot = 3
         *
         *  var fuLightType = LightType.Parallel;
         *
         *  switch ((int) asLightType)
         *  {
         *      case 1:
         *          fuLightType = LightType.Point;
         *          break;
         *      case 3:
         *          fuLightType = LightType.Spot;
         *          break;
         *  }
         *
         *  return new LightComponent
         *  {
         *      Active = true,
         *      Position = asPosition,
         *      ConeAngle = asConeAngle,
         *      ConeDirection = asConeDirection,
         *      Attenuation = asAttenuation,
         *      AmbientCoefficient = asAmbient.Length,
         *      Color = asColor,
         *      Type = fuLightType
         *  };
         * } */

        private Mesh GetMesh(int meshIndex)
        {
            Mesh fuMesh;

            if (_meshCache.TryGetValue(meshIndex, out fuMesh))
            {
                return(fuMesh);
            }

            // no mesh in cache
            var assimpMesh = _assimpScene.Meshes[meshIndex];

            var meshVertices = assimpMesh.Vertices;
            var meshNormals  = assimpMesh.Normals;
            var meshTexCords = assimpMesh.TextureCoordinateChannels;
            var meshFaces    = assimpMesh.Faces;

            var fuMeshVerticies = new float3[meshVertices.Count];
            var fuMeshNormals   = new float3[meshNormals.Count];
            var fuMeshTexCords  = new float2[meshTexCords.Length * 2];
            var fuMeshTriangles = new ushort[meshFaces.Count * 3];

            for (var i = 0; i < meshVertices.Count; i++)
            {
                // Evaluate mesh and ...
                var vertex  = new float3(meshVertices[i].X, meshVertices[i].Y, meshVertices[i].Z);
                var normal  = new float3(meshNormals[i].X, meshNormals[i].Y, meshNormals[i].Z);
                var texCord = new float2[meshTexCords.Length * meshTexCords[0].Count];

                // ... evaluate and set UVs
                foreach (var meshTexCord in meshTexCords)
                {
                    for (var k = 0; k < meshTexCord.Count; k++)
                    {
                        texCord[k] = new float2(meshTexCord[k].X, meshTexCord[k].Y);
                    }
                }

                // ... add it to components of Mesh
                fuMeshVerticies[i] = vertex;
                fuMeshNormals[i]   = normal;
                fuMeshTexCords     = texCord;
            }

            var count = 0;

            // Evaluate all faces and add them all to one ushort[]
            // TODO: This allocation is reversed (2, 1, 0) to satisfy FUSEE's rendering
            // TODO: Change this if your vertex is culled!!
            foreach (var face in meshFaces)
            {
                fuMeshTriangles[count]   = (ushort)face.Indices[2];
                fuMeshTriangles[++count] = (ushort)face.Indices[1];
                fuMeshTriangles[++count] = (ushort)face.Indices[0];
                ++count;
            }

            float3 min;
            float3 max;

            // TODO: Test if this method works!
            EvaluateAABB(fuMeshVerticies, out min, out max);

            // Create new Mesh
            fuMesh = new Mesh
            {
                Name        = assimpMesh.Name,
                Vertices    = fuMeshVerticies,
                BoundingBox = new AABBf(min, max),
                Normals     = fuMeshNormals,
                Triangles   = fuMeshTriangles,
                UVs         = fuMeshTexCords
            };

            // Add to cache
            _meshCache.Add(meshIndex, fuMesh);

            return(fuMesh);
        }