コード例 #1
0
        public override void Start()
        {
            string boidModel    = GetScriptCustomAttribute("boidModelResourceId");
            string boidCountStr = GetScriptCustomAttribute("boidCount");

            int boidCount = int.Parse(boidCountStr);

            for (int i = 0; i < boidCount; ++i)
            {
                GameObject newGameObject = new GameObject($"Boid ({i})");
                newGameObject.Visible         = true;
                newGameObject.transform.scale = new vec4(1.0f, 1.0f, 1.0f, 1.0f);

                //bird.obj.
                MeshComponent meshComponent = new MeshComponent(boidModel);

                newGameObject.AddComponent <MeshComponent>(meshComponent);

                meshComponent.Dispose();

                newGameObject.AddScript("FlockingAgent");

                m_boids.Add(newGameObject);
            }
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: Vexzal/ConceptualGameEngine
        void LoadScene()
        {
            gameScene = new Scene();
            GameObject CubeObject = new GameObject();

            CubeObject.name = "Cube";

            MeshComponent CubeMesh = new MeshComponent();

            CubeMesh.mesh = _assets.Cube;

            CubeObject.GetComponent <TransformComponent>().Transform.SetPosition(0, 0, 2);
            CubeObject.AddComponent(CubeMesh);

            GameObject PlaneObject = new GameObject();

            PlaneObject.name = "Plane";

            MeshComponent PlaneMesh = new MeshComponent();

            PlaneMesh.mesh = _assets.Plane;
            PlaneObject.AddComponent(PlaneMesh);

            gameScene.AddGameObject(CubeObject);
            gameScene.AddGameObject(PlaneObject);
        }
コード例 #3
0
ファイル: Tutorial.cs プロジェクト: griestopf/Fusee.Tutorial
        // Init is called on startup.
        public override void Init()
        {
            // Load the scene file "Cube.fus"
            SceneContainer sc = AssetStorage.Get <SceneContainer>("Cube.fus");

            // Extract the 'First' object of type 'MeshComponent' found in 'sc'`s list of 'Children' without
            // further specifying any search criterion ('c => true' means: any found MeshComponent will do).
            MeshComponent mc = sc.Children.FindComponents <MeshComponent>(c => true).First();

            // Generate a mesh from the MeshComponent's vertices, normals and triangles.
            _mesh = new Mesh
            {
                Vertices  = mc.Vertices,
                Normals   = mc.Normals,
                Triangles = mc.Triangles
            };

            var shader = RC.CreateShader(_vertexShader, _pixelShader);

            RC.SetShader(shader);
            _xformParam = RC.GetShaderParam(shader, "xform");
            _xform      = float4x4.Identity;

            // Set the clear color for the backbuffer
            RC.ClearColor = new float4(1, 1, 1, 1);
        }
コード例 #4
0
ファイル: GameObjectBuilder.cs プロジェクト: chargen/AGI-X0
        void buildAndAddRenderingMesh(GameObjectTemplate template, PhysicsComponent physicsComponent)
        {
            if (template.meshPath == "meta:fromMainShape")   // the mesh is derived from the mainshape
            {
                MeshWithExplicitFaces renderMesh;

                if (template.mainMassShapeType == "box")
                {
                    renderMesh = PlatonicFactory.createBox(template.mainMassDimensions[0], template.mainMassDimensions[1], template.mainMassDimensions[2]);
                }
                else
                {
                    throw new NotImplementedException("meta:fromMainShape mesh path is not implemented for shape " + template.meshPath + "!");
                }

                MeshComponent meshComponent = new MeshComponent();
                meshComponent.mesh = renderMesh;

                TransformedMeshComponent transformedMeshComponentForRendering = new TransformedMeshComponent();
                transformedMeshComponentForRendering.meshComponent = meshComponent;

                softwareRenderer.physicsAndMeshPairs.Add(new PhysicsComponentAndMeshPair(physicsComponent, transformedMeshComponentForRendering));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #5
0
        /*
        struct SurfaceOutput {
            half3 Albedo;
            half3 Normal;
            half3 Emission;
            half Specular;
            half Gloss;
            half Alpha;
        };
        */

        public ShaderCodeBuilder(MaterialComponent mc, MeshComponent mesh, WeightComponent wc = null)
        {
            if (wc != null)
            {
                _hasWeightMap = true;
                _nBones = wc.Joints.Count;
            }
            else
            {
                _nBones = 0;
            }

            float f1 = 1;
            f1.GetType();
            _normalizeNormals = true;
            if (mesh != null)
                AnalyzeMesh(mesh);
            else
            {
                _hasVertices = _hasNormals = _hasUVs = true;
            }
            AnalyzeMaterial(mc);

            StringBuilder vs = new StringBuilder();
            MeshInputDeclarations(vs);
            MatrixDeclarations(vs);
            VSBody(vs);
            _vs = vs.ToString();

            StringBuilder ps = new StringBuilder();
            PixelInputDeclarations(ps);
            PSBody(ps);
            _ps = ps.ToString();
        }
コード例 #6
0
        private IEnumerable <Tri> MeshTriangles(MeshComponent mesh)
        {
            if (mesh.Triangles == null || mesh.Triangles.Length == 0)
            {
                yield break;
            }

            float3[] verts = new float3[mesh.Vertices.Length];

            // transform all vertices to clip space
            for (int i = 0; i < verts.Length; i++)
            {
                float4 vClip = MVP * new float4(mesh.Vertices[i], 1.0f);
                vClip    = vClip / vClip.z;
                verts[i] = vClip.xyz;
            }

            for (int i = 0; i < mesh.Triangles.Length; i += 3)
            {
                var tri = new Tri
                {
                    p0 = verts[mesh.Triangles[i]],
                    p1 = verts[mesh.Triangles[i + 1]],
                    p2 = verts[mesh.Triangles[i + 2]],
                };
                if (PointClipped(tri.p0) && PointClipped(tri.p1) && PointClipped(tri.p2))
                {
                    continue;
                }
                yield return(tri);
            }
        }
コード例 #7
0
ファイル: PlaneActor.cs プロジェクト: lehmamic/gameprogcpp
 public PlaneActor(Game game) : base(game)
 {
     Scale = 10.0f;
     var mc = new MeshComponent(this)
     {
         Mesh = Game.Renderer.GetMesh("Assets/Plane.gpmesh")
     };
 }
コード例 #8
0
 public void RemoveWorldDynamicPrimitive(MeshComponent InMeshComponent)
 {
     if (bDisable == true)
     {
         return;
     }
     WorldDynamicPrimitiveList.Remove(InMeshComponent);
 }
コード例 #9
0
 private void AnalyzeMesh(MeshComponent mesh)
 {
     _hasVertices = (mesh.Vertices != null && mesh.Vertices.Length > 0);
     _hasNormals  = (mesh.Normals != null && mesh.Normals.Length > 0);
     _hasUVs      = (mesh.UVs != null && mesh.UVs.Length > 0);
     _hasColors   = false;
     // _hasColors = (mesh.Colors != null && mesh.Colors.Length > 0);
 }
コード例 #10
0
    private void Target()
    {
        Bounds         bounds               = MeshComponent.GetComponent <Renderer>().bounds;
        List <Vector3> cornerPoints         = GetAllCornerPoints(bounds);
        Rect           boundingViewportRect = GetBoundingViewportRect(cornerPoints, cam);

        CenterCameraOnViewportRect(cam, boundingViewportRect, paddingPercentage);
        SetDistanceFromPoint(cam, bounds.center, distance);
    }
コード例 #11
0
ファイル: S3DLoader.cs プロジェクト: polytronicgr/spriteboy
        /// <summary>
        /// Загрузка S3D-файла
        /// </summary>
        /// <param name="file">Файл</param>
        /// <returns>Загруженная модель</returns>
        public static Entity Load(string file)
        {
            byte[]       data = FileSystem.Read(file);
            BinaryReader f    = new BinaryReader(new MemoryStream(data));

            // Создание объекта
            Entity e = new Entity();

            // Поверхности
            int surfs = f.ReadUInt16();

            for (int s = 0; s < surfs; s++)
            {
                // Треугольники
                int verts = f.ReadUInt16() * 3;

                Vec3[]   positions = new Vec3[verts];
                Vec3[]   normals   = new Vec3[verts];
                Vec2[]   texcoords = new Vec2[verts];
                ushort[] indices   = new ushort[verts];

                // Чтение вершин треугольников
                for (int t = 0; t < verts; t++)
                {
                    Vec3 pos = new Vec3();
                    pos.X        = f.ReadSingle() * 0.015f;
                    pos.Y        = f.ReadSingle() * 0.015f;
                    pos.Z        = f.ReadSingle() * 0.015f;
                    positions[t] = pos;

                    normals[t] = Vec3.UnitY;

                    Vec2 uv = new Vec2();
                    uv.X         = f.ReadSingle();
                    uv.Y         = f.ReadSingle();
                    texcoords[t] = uv;
                }

                // Индексы
                for (int i = 0; i < indices.Length; i++)
                {
                    indices[i] = (ushort)i;
                }

                // Сохранение поверхности
                MeshComponent mc = new MeshComponent();
                mc.Indices   = indices;
                mc.Vertices  = positions;
                mc.TexCoords = texcoords;
                mc.Normals   = normals;
                e.AddComponent(mc);
            }

            f.Close();
            return(e);
        }
コード例 #12
0
ファイル: SceneObject.cs プロジェクト: xKiwii/CubyTower
 protected void parseModel()
 {
     components = model.Children.First().Components;
     foreach (var component in components)
     {
         if (component.GetType() == typeof(MaterialComponent)) { materialComponent = (MaterialComponent)component; }
         if (component.GetType() == typeof(TransformComponent)) { transformComponent = (TransformComponent)component; }
         if (component.GetType() == typeof(MeshComponent)) { meshComponent = (MeshComponent)component; }
     }
 }
コード例 #13
0
        private static Func <StudioVertex, string> GetVertSerializer(MeshComponent components)
        {
            switch (components)
            {
            case MeshComponent.Position | MeshComponent.Uv | MeshComponent.Rgb:
                return(vert => $"{vert.Position.X},{vert.Position.Y},{vert.Position.Z},{vert.TexCoordX},{vert.TexCoordY},0,255,0");

            default:
                throw new NotImplementedException();
            }
        }
コード例 #14
0
        void OnCreate()
        {
            Random random = new Random();

            MeshComponent    meshComponent = GetComponent <MeshComponent>();
            MaterialInstance material      = meshComponent.Mesh.GetMaterial(0);
            float            r             = (float)random.NextDouble();
            float            g             = (float)random.NextDouble();
            float            b             = (float)random.NextDouble();

            material.Set("u_AlbedoColor", new Vector3(r, g, b));
        }
コード例 #15
0
ファイル: Main.cs プロジェクト: hahnmatt/DIEAbgabe
        public static Mesh LoadMesh(string assetName)
        {
            SceneContainer sc = AssetStorage.Get <SceneContainer>(assetName);
            MeshComponent  mc = sc.Children.FindComponents <MeshComponent>(c => true).First();

            return(new Mesh
            {
                Vertices = mc.Vertices,
                Normals = mc.Normals,
                Triangles = mc.Triangles
            });
        }
コード例 #16
0
            public void Test(MeshComponent mc)
            {
                if (mc.Triangles != null && mc.Triangles.Length > 2)
                {
                    float4x4 mvp = State.Projection * State.View * State.Model;
                    float4   a   = mvp * new float4(mc.Vertices[mc.Triangles[0]], 1);
                    float4   b   = mvp * new float4(mc.Vertices[mc.Triangles[1]], 1);
                    float4   c   = mvp * new float4(mc.Vertices[mc.Triangles[2]], 1);

                    YieldItem(new Tri {
                        A = a.xy / a.w, B = b.xy / b.w, C = c.xy / c.w
                    });
                }
            }
コード例 #17
0
        public void OnMesh(MeshComponent meshComponent)
        {
            AABBf box = _state.ModelView * meshComponent.BoundingBox;

            if (!_boxValid)
            {
                _result   = box;
                _boxValid = true;
            }
            else
            {
                _result = AABBf.Union((AABBf)_result, box);
            }
        }
コード例 #18
0
        public Mesh MakeMesh(MeshComponent mc)
        {
            Mesh rm;

            rm = new Mesh()
            {
                Colors    = null,
                Normals   = mc.Normals,
                UVs       = mc.UVs,
                Vertices  = mc.Vertices,
                Triangles = mc.Triangles
            };
            return(rm);
        }
コード例 #19
0
 void OnMesh(MeshComponent mesh)
 {
     foreach (var tri in MeshTriangles(mesh))
     {
         float s, t;
         if (PointInTriangle(_pickPoint, tri, out s, out t))
         {
             _pickResults.Add(new PickResult
             {
                 Node        = CurrentNode,
                 PickPntClip = new float3(_pickPoint.x, _pickPoint.y,
                                          tri.p0.z * s + tri.p1.z * t + tri.p2.z * (1.0f - s - t))
             });
         }
     }
 }
コード例 #20
0
ファイル: Tutorial.cs プロジェクト: griestopf/Fusee.Tutorial
        private Mesh LookupMesh(MeshComponent mc)
        {
            Mesh mesh;

            if (!_meshes.TryGetValue(mc, out mesh))
            {
                mesh = new Mesh
                {
                    Vertices  = mc.Vertices,
                    Normals   = mc.Normals,
                    Triangles = mc.Triangles
                };
                _meshes[mc] = mesh;
            }
            return(mesh);
        }
コード例 #21
0
        public override void OnInspectorGUI()
        {
            if (HasErrors())
            {
                return;
            }

            BeginEditing();

            OnPreInspectorGUI();

            EditorGUI.BeginDisabledGroup(_useLegacyMeshProperty.boolValue);
            var mf = MeshComponent.GetComponent <MeshFilter>();

            if (mf)
            {
                EditorGUI.BeginChangeCheck();
                var newMesh = (Mesh)EditorGUILayout.ObjectField("Mesh", mf.sharedMesh, typeof(Mesh), true);
                if (EditorGUI.EndChangeCheck())
                {
                    mf.sharedMesh = newMesh;
                }
            }
            EditorGUI.EndDisabledGroup();

            PropertyField(_useLegacyMeshProperty, rebuildMesh: true, onChanging: () => {
                if (mf)
                {
                    mf.sharedMesh = _useLegacyMeshProperty.boolValue
                                                ? new Mesh {
                        name = $"{target.name} (Generated)"
                    }                                   // when switching to legacy mesh, instantiate new mesh
                                                : null; // when switching to referenced mesh, reset reference.
                    EndEditing();
                }
            });
            EditorGUI.BeginDisabledGroup(!_useLegacyMeshProperty.boolValue);
            PropertyField(_sidesProperty, rebuildMesh: true);
            EditorGUI.EndDisabledGroup();

            base.OnInspectorGUI();

            EndEditing();
        }
コード例 #22
0
    public void InitializeMeshAsGrid()
    {
        int vertexCountX     = HorizontalCellCount + 1;
        int vertexCountY     = VerticalCellCount + 1;
        int totalVertexCount = (vertexCountX + vertexCountY) * 4;

        Vector3[] vertices  = new Vector3[totalVertexCount];
        int[]     triangles = new int[(int)(totalVertexCount * 1.5f)];

        int vertexIndex   = 0;
        int triangleIndex = 0;

        TriangulateVertical(vertexCountX, VerticalCellCount, 0, ref triangleIndex, ref vertexIndex, triangles, vertices);
        TriangulateHorizontal(HorizontalCellCount, vertexCountY, vertexIndex, ref triangleIndex, ref vertexIndex, triangles, vertices);

        MeshComponent.Clear();
        MeshComponent.vertices  = vertices;
        MeshComponent.triangles = triangles;
    }
コード例 #23
0
        public Mesh(MeshComponent components)
        {
            positions       = new List <vec3>();
            indices         = new List <int>();
            this.components = components;

            if ((components & MeshComponent.normals) != 0)
            {
                normals = new List <vec3>();
            }
            if ((components & MeshComponent.uvs) != 0)
            {
                uvs = new List <vec2>();
            }
            if ((components & MeshComponent.colors) != 0)
            {
                colors = new List <vec3>();
            }
        }
コード例 #24
0
 protected void parseModel()
 {
     components = model.Children.First().Components;
     foreach (var component in components)
     {
         if (component.GetType() == typeof(MaterialComponent))
         {
             materialComponent = (MaterialComponent)component;
         }
         if (component.GetType() == typeof(TransformComponent))
         {
             transformComponent = (TransformComponent)component;
         }
         if (component.GetType() == typeof(MeshComponent))
         {
             meshComponent = (MeshComponent)component;
         }
     }
 }
コード例 #25
0
        public void RenderMesh(MeshComponent meshComponent)
        {
            Mesh rm;

            if (!_meshMap.TryGetValue(meshComponent, out rm))
            {
                rm = MakeMesh(meshComponent);
                _meshMap.Add(meshComponent, rm);
            }

            if (null != _state.Effect.GetEffectParam(ShaderCodeBuilder.LightDirectionName))
            {
                RenderWithLights(rm, _state.Effect);
            }
            else
            {
                _state.Effect.RenderMesh(rm);
            }
        }
コード例 #26
0
        public void GenerateMap()
        {
            //float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, noiseScale);
            float[,] noiseMap = Noise.GenerateNoiseMap(MapWidth, MapHeight, Seed, NoiseScale, Octaves, Persistance, Lacunarity, Offset);

            uint width  = (uint)noiseMap.GetLength(0);
            uint height = (uint)noiseMap.GetLength(1);

            Texture2D texture = new Texture2D(width, height);

            Vector4[] colorMap = new Vector4[width * height];
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    colorMap[x + y * width] = Vector4.Lerp(Color.Black, Color.White, noiseMap[x, y]);
                }
            }

            texture.SetData(colorMap);

            Console.WriteLine("HasComponent - TransformComponent = {0}", HasComponent <TransformComponent>());
            Console.WriteLine("HasComponent - ScriptComponent = {0}", HasComponent <ScriptComponent>());
            Console.WriteLine("HasComponent - MeshComponent = {0}", HasComponent <MeshComponent>());

            MeshComponent meshComponent = GetComponent <MeshComponent>();

            if (meshComponent == null)
            {
                Console.WriteLine("MeshComponent is null!");
                meshComponent = CreateComponent <MeshComponent>();
            }
            meshComponent.Mesh = MeshFactory.CreatePlane(1.0f, 1.0f);

            Console.WriteLine("Mesh has {0} materials!", meshComponent.Mesh.GetMaterialCount());

            MaterialInstance material = meshComponent.Mesh.GetMaterial(1);

            material.Set("u_AlbedoTexToggle", 1.0f);
            material.Set("u_AlbedoTexture", texture);
        }
コード例 #27
0
ファイル: ScenePicker.cs プロジェクト: reliefpfeiler42/Fusee
        public void PickMesh(MeshComponent meshComponent)
        {
            // Mesh rm;

            // TODO: DO THE PICK TEST HERE
            // foreach triangle
            // {
            //   if (triangle is hit by pickpos)
            //   {
            //     YieldItem(new PickResult
            //          {
            //              Mesh = meshComponent,
            //              Node = CurrentNode,
            //              Triangle = TODO,
            //              WA = TODO,
            //              WB = TODO,
            //              WC = TODO
            //          });
            //   }
            // }
        }
コード例 #28
0
            public int Serialize(MeshComponent components, float[] dest)
            {
                var destIndex = 0;

                if (components.HasFlag(MeshComponent.Position))
                {
                    dest[destIndex++] = Position.X;
                    dest[destIndex++] = Position.Y;
                    dest[destIndex++] = Position.Z;
                }

                if (components.HasFlag(MeshComponent.Normal))
                {
                    dest[destIndex++] = Normal.X;
                    dest[destIndex++] = Normal.Y;
                    dest[destIndex++] = Normal.Z;
                }

                if (components.HasFlag(MeshComponent.Uv))
                {
                    dest[destIndex++] = TexCoord.X;
                    dest[destIndex++] = TexCoord.Y;
                }

                if (components.HasFlag(MeshComponent.Uv2))
                {
                    dest[destIndex++] = LightmapCoord.X;
                    dest[destIndex++] = LightmapCoord.Y;
                }

                if (components.HasFlag(MeshComponent.Alpha))
                {
                    dest[destIndex++] = Alpha;
                }

                return(destIndex);
            }
コード例 #29
0
        // Restores components in this entity from string, make sure entity is added to EntityManager
        private void DeserializeComponents(string[] componentLines)
        {
            int lineCount = 0;

            if (HasComponent <TransformComponent>())
            {
                Transform = MessagePackSerializer.Deserialize <TransformComponent>(MessagePackSerializer.FromJson(componentLines[lineCount++]));
            }
            if (HasComponent <PhysicsComponent>())
            {
                Physics = MessagePackSerializer.Deserialize <PhysicsComponent>(MessagePackSerializer.FromJson(componentLines[lineCount++]));
            }
            if (HasComponent <CollisionComponent>())
            {
                Collision = MessagePackSerializer.Deserialize <CollisionComponent>(MessagePackSerializer.FromJson(componentLines[lineCount++]));
            }
            if (HasComponent <MeshComponent>())
            {
                Mesh = MessagePackSerializer.Deserialize <MeshComponent>(MessagePackSerializer.FromJson(componentLines[lineCount++]));
            }

            // Try set component to default after deserializing to initialize properties that have to be initialized
            Mesh.TrySetDefaults();
        }
コード例 #30
0
        private void SetupRenderableEntity(IEntity entity)
        {
            MeshComponent meshComponent = entity.GetComponent <MeshComponent>();
            OgreEntity    ogreEntity    = _sceneManager.createEntity(meshComponent.MeshName);

            SceneNode sceneNode = _sceneManager.getRootSceneNode().createChildSceneNode(/* TODO: Name Component? */);

            PositionComponent transformComponent = entity.GetComponent <PositionComponent>();

            sceneNode.setPosition(transformComponent.Position);

            if (entity.HasComponent <ScaleComponent>())
            {
                ScaleComponent scaleComponent = entity.GetComponent <ScaleComponent>();
                sceneNode.setScale(scaleComponent.Scale);
            }

            RenderableComponent renderableComponent = entity.GetComponent <RenderableComponent>();

            renderableComponent.OgreEntity = ogreEntity;
            renderableComponent.SceneNode  = sceneNode;

            entity.IsActive = true;
        }
コード例 #31
0
ファイル: SG_Gate.cs プロジェクト: illuminati360/AltSpaceMREs
        public void AnalyzeGateStructure()
        {
            uint meshComponentCount = ObjectPrivate.GetComponentCount(ComponentType.MeshComponent);
            Dictionary <string, MeshComponent> meshes = new Dictionary <string, MeshComponent>();

            for (uint i = 0; i < meshComponentCount; i++)
            {
                MeshComponent mc = (MeshComponent)ObjectPrivate.GetComponent(ComponentType.MeshComponent, i);
                if (!mc.IsScriptable)
                {
                    continue;
                }

                string name = thisModelTranslator.GetRealMeshName(mc.Name);
                meshes[name] = mc;
            }

            chevrons       = GatherLights(meshes, "Chevron");
            symbols        = GatherLights(meshes, "Symbol");
            symbolLitState = new bool[symbols.Count];
            FlushLights();

            Log.Write(LogLevel.Info, "Chevrons found:" + chevrons.Count + ", Symbols found: " + symbols.Count);
        }
コード例 #32
0
ファイル: Renderer.cs プロジェクト: xKiwii/CubyTower
 private Mesh LookupMesh(MeshComponent mc)
 {
     Mesh mesh;
     if (!_meshes.TryGetValue(mc, out mesh))
     {
         mesh = new Mesh
         {
             Vertices = mc.Vertices,
             Normals = mc.Normals,
             UVs = mc.UVs,
             Triangles = mc.Triangles,
         };
         _meshes[mc] = mesh;
     }
     return mesh;
 }
コード例 #33
0
ファイル: Renderer.cs プロジェクト: xKiwii/CubyTower
 void OnMesh(MeshComponent mesh)
 {
     RC.Render(LookupMesh(mesh));
 }