예제 #1
0
        private Storyboard CreatetAnimation(GenieEffectType effectType)
        {
            double aspect = transitionContrainer.ActualWidth / transitionContrainer.ActualHeight;

            MeshGeometry3D mesh = MeshCreator.CreateMesh(SidePoints, SidePoints);

            mesh.Positions          = new RectangularMeshFiller().FillMesh(SidePoints, SidePoints, aspect);
            _slidingScreen.Geometry = mesh;
            _slidingScreen.Material = new DiffuseMaterial(CreateBrush(contentContrainer));
            PerspectiveCamera camera     = _viewport.Camera as PerspectiveCamera;
            double            angle      = camera.FieldOfView / 2;
            double            cameraZPos = (aspect / 2) / Math.Tan(angle * Math.PI / 180);

            camera.Position = new Point3D(0, 0, cameraZPos);

            Storyboard     storyboard = (_viewport.Resources["GenieAnim"] as Storyboard).Clone();
            GenieAnimation anim       = storyboard.Children[0] as GenieAnimation;

            anim.Duration    = new Duration(TimeSpan.FromSeconds(1));
            anim.EffectType  = effectType;
            anim.AspectRatio = aspect;

            animationContainer.Children.Add(_viewport);
            animationContainer.Visibility   = Visibility.Visible;
            transitionContrainer.Visibility = Visibility.Hidden;

            return(storyboard);
        }
예제 #2
0
        void Awake()
        {
            // We will create a cube, so we set 12 triangles (6 sides á 2 triangles) and 8 vertices.
            // To do a cube with proper shading, we should actually create 4 vertices per side and have
            // normals pointing outwards, but for this example let's keep it simple.
            meshCreator = new MeshCreator(12, 8);

            // Create the vertices
            var behindUpperLeft  = new MeshVertex(new Vector3(-1, 1, 1), Vector3.zero, Color.white);
            var behindUpperRight = new MeshVertex(new Vector3(1, 1, 1), Vector3.zero, Color.white);
            var behindLowerLeft  = new MeshVertex(new Vector3(-1, -1, 1), Vector3.zero, Color.white);
            var behindLowerRight = new MeshVertex(new Vector3(1, -1, 1), Vector3.zero, Color.white);
            var frontUpperLeft   = new MeshVertex(new Vector3(-1, 1, -1), Vector3.zero, Color.white);
            var frontUpperRight  = new MeshVertex(new Vector3(1, 1, -1), Vector3.zero, Color.white);
            var frontLowerLeft   = new MeshVertex(new Vector3(-1, -1, -1), Vector3.zero, Color.white);
            var frontLowerRight  = new MeshVertex(new Vector3(1, -1, -1), Vector3.zero, Color.white);

            // Create the quads
            meshCreator.AddQuad(frontUpperLeft, frontUpperRight, frontLowerRight, frontLowerLeft);
            meshCreator.AddQuad(behindUpperRight, behindUpperLeft, behindLowerLeft, behindLowerRight);
            meshCreator.AddQuad(frontUpperRight, behindUpperRight, behindLowerRight, frontLowerRight);
            meshCreator.AddQuad(frontUpperLeft, frontLowerLeft, behindLowerLeft, behindUpperLeft);
            meshCreator.AddQuad(frontUpperLeft, behindUpperLeft, behindUpperRight, frontUpperRight);
            meshCreator.AddQuad(frontLowerLeft, frontLowerRight, behindLowerRight, behindLowerLeft);

            // Create a new mesh and set it in the mesh filter
            meshFilter            = GetComponent <MeshFilter>();
            meshFilter.sharedMesh = meshCreator.CreateMesh();
            meshFilter.sharedMesh.RecalculateNormals();
        }
예제 #3
0
    void Update()
    {
        Vector3[] vertices = new Vector3[latitudeLineCount * longitudeLineCount];
        int       vtxIndex = 0;

        for (int j = 0; j < latitudeLineCount; j++)
        {
            float lat = 180 * ((float)(j + 1) / latitudeLineCount);

            for (int i = 0; i < longitudeLineCount; i++)
            {
                float lon = 360 * ((float)i / longitudeLineCount);

                Vector3 cartesian = new Vector3(
                    radius * Mathf.Cos(lat) * Mathf.Cos(lon),
                    radius * Mathf.Cos(lat) * Mathf.Sin(lon),
                    radius * Mathf.Sin(lat)
                    );

                vertices[vtxIndex++] = cartesian;
            }
        }

        MeshCreator mc = new MeshCreator();

        for (int i = 2; i < vertices.Length; i++)
        {
            mc.BuildTriangle(vertices[i - 2], vertices[i - 1], vertices[i]);
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #4
0
    void CreatePlane(int length, int width)
    {
        List <Vector3> vertices = new List <Vector3>();

        //Generate grid of vertices
        for (int x = 0; x <= length; x++)
        {
            for (int z = 0; z <= width; z++)
            {
                Vector3 noiseVert = new Vector3(((float)x) / rangex, ((float)z) / rangey, noiseAmt);
                vertices.Add(new Vector3(x * offset, Perlin.Noise(noiseVert) * intensity, z * offset));
            }
        }

        //Build Squares
        //Iterate through all but first x vert, all bust last y vert
        for (int x = 1; x <= length; x++)
        {
            for (int z = 0; z < length; z++)
            {
                mc.BuildTriangle(vertices[x * (width + 1) + (z + 1)], vertices[x * (width + 1) + z], vertices[(x - 1) * (width + 1) + (z + 1)]);
                mc.BuildTriangle(vertices[x * (width + 1) + z], vertices[(x - 1) * (width + 1) + z], vertices[(x - 1) * (width + 1) + (z + 1)]);
            }
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #5
0
    private void FixedUpdate()
    {
        timer += Time.deltaTime * timeMod;

        if (timer > 255)
        {
            timer = 0;
        }


        MeshFilter  meshFilter = this.GetComponent <MeshFilter>();  // one submesh for each face
        MeshCreator mc         = new MeshCreator();

        Vector3 cubeSize = size * 0.5f;

        float noiseValueT0 = Perlin.Noise((pos.x + cubeSize.x) / posMod, (pos.y - cubeSize.z) / posMod, timer);
        float noiseValueT1 = Perlin.Noise((pos.x - cubeSize.x) / posMod, (pos.y - cubeSize.z) / posMod, timer);
        float noiseValueT2 = Perlin.Noise((pos.x - cubeSize.x) / posMod, (pos.y + cubeSize.z) / posMod, timer);
        float noiseValueT3 = Perlin.Noise((pos.x + cubeSize.x) / posMod, (pos.y + cubeSize.z) / posMod, timer);
        //float noiseValueT0 = Perlin.Noise((pos.x + cubeSize.x) * posMod, (pos.y - cubeSize.z) * posMod, timer);
        //float noiseValueT1 = Perlin.Noise((pos.x - cubeSize.x) * posMod, (pos.y - cubeSize.z) * posMod, timer);
        //float noiseValueT2 = Perlin.Noise((pos.x - cubeSize.x) * posMod, (pos.y + cubeSize.z) * posMod, timer);
        //float noiseValueT3 = Perlin.Noise((pos.x + cubeSize.x) * posMod, (pos.y + cubeSize.z) * posMod, timer);

        // top of the cube
        // t0 is top left point
        Vector3 t0 = new Vector3(cubeSize.x, cubeSize.y + modifier * noiseValueT0, -cubeSize.z);
        Vector3 t1 = new Vector3(-cubeSize.x, cubeSize.y + modifier * noiseValueT1, -cubeSize.z);
        Vector3 t2 = new Vector3(-cubeSize.x, cubeSize.y + modifier * noiseValueT2, cubeSize.z);
        Vector3 t3 = new Vector3(cubeSize.x, cubeSize.y + modifier * noiseValueT3, cubeSize.z);

        // bottom of the cube
        Vector3 b0 = new Vector3(cubeSize.x, -cubeSize.y, -cubeSize.z);
        Vector3 b1 = new Vector3(-cubeSize.x, -cubeSize.y, -cubeSize.z);
        Vector3 b2 = new Vector3(-cubeSize.x, -cubeSize.y, cubeSize.z);
        Vector3 b3 = new Vector3(cubeSize.x, -cubeSize.y, cubeSize.z);

        // Top square
        mc.BuildTriangle(t0, t1, t2);
        mc.BuildTriangle(t0, t2, t3);

        // Bottom square
        mc.BuildTriangle(b2, b1, b0);
        mc.BuildTriangle(b3, b2, b0);

        // Back square
        mc.BuildTriangle(b0, t1, t0);
        mc.BuildTriangle(b0, b1, t1);

        mc.BuildTriangle(b1, t2, t1);
        mc.BuildTriangle(b1, b2, t2);

        mc.BuildTriangle(b2, t3, t2);
        mc.BuildTriangle(b2, b3, t3);

        mc.BuildTriangle(b3, t0, t3);
        mc.BuildTriangle(b3, b0, t0);

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        MeshFilter meshFilter = this.GetComponent <MeshFilter>();
        // one submesh for each face
        Vector3 center = new Vector3(0, 0, 0);

        mc.Clear(); // Clear internal lists and mesh



        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < col; j++)
            {
                center.Set(j * size.x * (float)distance,
                           0,
                           i * size.z * (float)distance);

                vfxList[i, j].transform.position = new Vector3(j * size.x * (float)distance, 0, i * size.z * (float)distance);
                CreateCube(center, center.x, center.z, i, j);
            }
        }

        if (!animateVFX)
        {
            meshFilter.mesh = mc.CreateMesh();
        }
    }
예제 #7
0
 void DrawLines()
 {
     //Uncomment the lines below to draw gizmos lines
     /* for (int i=0; i<epd.total; i++) */
     /*  Debug.DrawLine(transform.position, epd.end_points[i], Color.red); */
     mcr.CreateMesh(epd);
 }
예제 #8
0
 private void recreateVoronoiMeshes()
 {
     meshesVoronoi.clear();
     for (int i = 0; i < voronoi.polygons.Count; i++)
     {
         meshesVoronoi.CreateMesh(voronoi.polygons[i], new Vector3(0, 0, -1), Random.ColorHSV());
     }
 }
예제 #9
0
    void UpdateChunk()
    {
        rendered = true;

        MeshInfo mesh_info = new MeshInfo();

        mesh_info = MeshCreator.CreateMesh(this, mesh_info);
        RenderMesh(mesh_info);
    }
예제 #10
0
    protected void Update()
    {
        meshCreator.Clear();

        Vector3 center = transform.localPosition;

        CreateCube(center, Time.deltaTime);

        meshFilter.mesh = meshCreator.CreateMesh();
    }
예제 #11
0
    public void DoRender()
    {
        if (m_ShareMeshData == null)
        {
            m_ShareMeshData = s_ShareMeshCreator.CreateMesh(m_MeshName);
        }

        if (m_ShareMeshData != null)
        {
            m_ShareMeshData.Draw(this.gameObject);
        }
    }
예제 #12
0
    void Update()
    {
        mc.Clear();

        // add vertices
        for (int i = 0; i <= width; i++)
        {
            float x = i * squareSize;
            for (int j = 0; j <= depth; j++)
            {
                float z = j * squareSize;

                // compute noise at given space time point
                float noiseOut = Perlin.Noise(noiseScale.x * i, noiseScale.y * Time.time, noiseScale.z * j);

                // normalize noise
                noiseOut += 1;
                noiseOut /= 2;

                // compute y-value from noise
                float y = noiseOut * maxHeight;

                // compute uv
                float u = (float)i / width;
                float v = (float)j / depth;

                // compute color from noise

                Color color = minColor + noiseOut * (maxColor - minColor);

                // add the vertex
                vertices[i, j] = new ColoredPoint(x, y, z, color.r, color.g, color.b);
            }
        }

        // build triangles out of those vertices
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < depth; j++)
            {
                ColoredPoint a = vertices[i, j];
                ColoredPoint b = vertices[i + 1, j];
                ColoredPoint c = vertices[i, j + 1];
                ColoredPoint d = vertices[i + 1, j + 1];

                mc.BuildTriangle(d, b, a);
                mc.BuildTriangle(c, d, a);
            }
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #13
0
    // Update is called once per frame
    void Update()
    {
        if (UpdateOnTick)
        {
            MeshFilter  meshFilter = this.GetComponent <MeshFilter>();
            MeshCreator mc         = new MeshCreator();
            mc.bumpiness = bumpiness;

            GenerateMesh(mc);

            meshFilter.mesh    = mc.CreateMesh();
            MeshCol.sharedMesh = meshFilter.mesh;
        }
    }
예제 #14
0
    private void Update()
    {
        // Clear the mesh data
        meshCreator.Clear();

        // Loop to obtain grids of terrain
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < width; ++y)
            {
                CreateTerrainSqure(x, y);
            }
        }
        meshFilter.mesh = meshCreator.CreateMesh();
    }
예제 #15
0
    public void CreateAgent(Agent agent, Transform parentTransform, Material mat, int speciesId, bool elevate, string tagName, float zAxis)
    {
        GameObject   newObject    = new GameObject(agent.AgentName);
        MeshRenderer meshRenderer = (MeshRenderer)newObject.AddComponent(typeof(MeshRenderer));
        MeshFilter   meshFilter   = (MeshFilter)newObject.AddComponent(typeof(MeshFilter));
        MeshCollider meshCollider = (MeshCollider)newObject.AddComponent <MeshCollider>();


        Debug.Log("----> Agent's attributes are : " + agent.Attributes.Count);

        foreach (AgentAttribute a in agent.Attributes)
        {
            Debug.Log("Attribute name is: " + a.name);
        }

        newObject.GetComponent <Transform>().SetParent(parentTransform);
        float elvation = elevate ? agent.Height : 0;

        meshFilter.mesh = meshCreator.CreateMesh(elvation, agent.AgentCoordinate.GetVector2Coordinates());
        //newObject.GetComponent<MeshFilter>().mesh = meshCreator.CreateMesh(agent.height, agent.ConvertVertices());

        meshFilter.mesh.name = "CustomMesh";
        //newGameObject.GetComponent<MeshFilter>().mesh = meshCreator.CreateMesh(30, agent.ConvertVertices());
        //mat.color = agent.color.getColorFromGamaColor();
        meshRenderer.material   = mat;
        meshCollider.sharedMesh = meshFilter.mesh;

        Vector3 posi = agent.Location;

        posi.y = -posi.y;

        //posi = uiManager.GetComponent<UIManager>().worldToUISpace(canvas, posi);

        RectTransform rt = (newObject.AddComponent <RectTransform>()).GetComponent <RectTransform>();

        rt.anchorMin = SceneManager.AnchorMin;
        rt.anchorMax = SceneManager.AnchorMax;
        rt.pivot     = SceneManager.Pivot;

        newObject.GetComponent <RectTransform>().anchoredPosition = new Vector3(0, 0, 0);
        posi = newObject.GetComponent <RectTransform>().localPosition;
        newObject.GetComponent <RectTransform>().localPosition = new Vector3(posi.x, posi.y, zAxis);

        SetAgentTag(newObject, tagName);
        AttacheCode(newObject, speciesId, agent);
        AddAgentToContexte(agent.Species, newObject);
    }
예제 #16
0
    // Update is called once per frame
    void Update()
    {
        MeshFilter meshFilter = this.GetComponent <MeshFilter>();
        // one submesh for each face
        Vector3 center = new Vector3(0, 0, 0);

        mc.Clear(); // Clear internal lists and mesh

        for (int i = 0; i < cubeCout; i++)
        {
            // center.Set(i * size.x * (float)1.2 * Mathf.PI, 0, i * size.z * (float)1.2 * Mathf.PI);
            center.Set(Mathf.Sin((360 / cubeCout) * i * Mathf.PI / 180) * radius, 0, Mathf.Cos((360 / cubeCout) * i * Mathf.PI / 180) * radius);
            CreateCube(center, i);
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #17
0
    // Update is called once per frame
    void Update()
    {
        MeshFilter meshFilter = this.GetComponent <MeshFilter>();
        // one submesh for each face
        Vector3 center = new Vector3(0, 0, 0);

        mc.Clear(); // Clear internal lists and mesh

        for (int row = 0; row < 50; row++)
        {
            for (int col = 0; col < 50; col++)
            {
                center.Set(col * size.x, 0, row * size.z);
                CreateCube(center);
            }
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #18
0
    private void Start()
    {
        MeshFilter  meshFilter = this.GetComponent <MeshFilter>();
        MeshCreator mc         = new MeshCreator(); // one submesh for each face

        Vector3 cubeSize = size * 0.5f;

        // top of the cube
        // t0 is top left point
        Vector3 t0 = new Vector3(cubeSize.x, cubeSize.y, -cubeSize.z);
        Vector3 t1 = new Vector3(-cubeSize.x, cubeSize.y, -cubeSize.z);
        Vector3 t2 = new Vector3(-cubeSize.x, cubeSize.y, cubeSize.z);
        Vector3 t3 = new Vector3(cubeSize.x, cubeSize.y, cubeSize.z);

        // bottom of the cube
        Vector3 b0 = new Vector3(cubeSize.x, -cubeSize.y, -cubeSize.z);
        Vector3 b1 = new Vector3(-cubeSize.x, -cubeSize.y, -cubeSize.z);
        Vector3 b2 = new Vector3(-cubeSize.x, -cubeSize.y, cubeSize.z);
        Vector3 b3 = new Vector3(cubeSize.x, -cubeSize.y, cubeSize.z);

        // Top square
        mc.BuildTriangle(t0, t1, t2);
        mc.BuildTriangle(t0, t2, t3);

        // Bottom square
        mc.BuildTriangle(b2, b1, b0);
        mc.BuildTriangle(b3, b2, b0);

        // Back square
        mc.BuildTriangle(b0, t1, t0);
        mc.BuildTriangle(b0, b1, t1);

        mc.BuildTriangle(b1, t2, t1);
        mc.BuildTriangle(b1, b2, t2);

        mc.BuildTriangle(b2, t3, t2);
        mc.BuildTriangle(b2, b3, t3);

        mc.BuildTriangle(b3, t0, t3);
        mc.BuildTriangle(b3, b0, t0);

        meshFilter.mesh = mc.CreateMesh();
    }
    private void GenerateTerrainMesh()
    {
        // Generate Squares
        for (int x = 0; x < meshWidth; x++)
        {
            for (int y = 0; y < meshLength; y++)
            {
                // Create Vertices
                Vector3 t0 = new Vector3(squareSize.x / 2, 0, -squareSize.y / 2);  // top left
                Vector3 t1 = new Vector3(-squareSize.x / 2, 0, -squareSize.y / 2); // bottom left
                Vector3 t2 = new Vector3(-squareSize.x / 2, 0, squareSize.y / 2);  // bottom right
                Vector3 t3 = new Vector3(squareSize.x / 2, 0, squareSize.y / 2);   // top right

                // Shift Vertices to match point on mesh
                Vector3 offset = new Vector3(x * squareSize.x, 0, y * squareSize.y);
                t0 += offset;
                t1 += offset;
                t2 += offset;
                t3 += offset;

                // Add perlin variable to heights
                t0.y = Mathf.PerlinNoise(t0.x * perlinScaleFactor, t0.z * perlinScaleFactor) * heightStretchFactor;
                t1.y = Mathf.PerlinNoise(t1.x * perlinScaleFactor, t1.z * perlinScaleFactor) * heightStretchFactor;
                t2.y = Mathf.PerlinNoise(t2.x * perlinScaleFactor, t2.z * perlinScaleFactor) * heightStretchFactor;
                t3.y = Mathf.PerlinNoise(t3.x * perlinScaleFactor, t3.z * perlinScaleFactor) * heightStretchFactor;

                // Todo - Make volcanos
                float volcanoModifiedHeight = volcanoHeight * heightStretchFactor;
                t0.y = t0.y > volcanoModifiedHeight ? t0.y - (t0.y - volcanoModifiedHeight) * volcanoDipFactor : t0.y;
                t1.y = t1.y > volcanoModifiedHeight ? t1.y - (t1.y - volcanoModifiedHeight) * volcanoDipFactor : t1.y;
                t2.y = t2.y > volcanoModifiedHeight ? t2.y - (t2.y - volcanoModifiedHeight) * volcanoDipFactor : t2.y;
                t3.y = t3.y > volcanoModifiedHeight ? t3.y - (t3.y - volcanoModifiedHeight) * volcanoDipFactor : t3.y;

                // Builds Triangle
                _meshCreator.BuildTriangle(t0, t1, t2);
                _meshCreator.BuildTriangle(t0, t2, t3);
            }
        }

        // Build Mesh
        _meshFilter.mesh = _meshCreator.CreateMesh();
    }
예제 #20
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        EditorGUI.BeginChangeCheck();

        GUILayout.Label(" ");
        if (GUILayout.Button("Update 3D mesh"))
        {
            Undo.RecordObject(myCreator, "Update 3D mesh");
            myCreator.UpdateMesh();
        }
        GUILayout.Label(" ");
        GUILayout.Label("Options to manipulate the mesh on the spline.");
        GUILayout.Label(" ");
        if (GUILayout.Button("Generate 3D Mesh"))
        {
            Undo.RecordObject(myCreator, "Generate 3D Mesh");
            myCreator.CreateMesh();
        }
    }
예제 #21
0
    void Update()
    {
        mc.Clear();

        Vector3 cubeSize = size * 0.5f;

        // top of the cube
        Vector3 t0 = new Vector3(cubeSize.x, cubeSize.y, -cubeSize.z);
        Vector3 t1 = new Vector3(-cubeSize.x, cubeSize.y, -cubeSize.z);
        Vector3 t2 = new Vector3(-cubeSize.x, cubeSize.y, cubeSize.z);
        Vector3 t3 = new Vector3(cubeSize.x, cubeSize.y, cubeSize.z);

        // bottom of the cube
        Vector3 b0 = new Vector3(cubeSize.x, -cubeSize.y, -cubeSize.z);
        Vector3 b1 = new Vector3(-cubeSize.x, -cubeSize.y, -cubeSize.z);
        Vector3 b2 = new Vector3(-cubeSize.x, -cubeSize.y, cubeSize.z);
        Vector3 b3 = new Vector3(cubeSize.x, -cubeSize.y, cubeSize.z);

        // Top square
        mc.BuildTriangle(t0, t1, t2);
        mc.BuildTriangle(t0, t2, t3);

        // Bottom square
        mc.BuildTriangle(b2, b1, b0);
        mc.BuildTriangle(b3, b2, b0);

        // Back square
        mc.BuildTriangle(b0, t1, t0);
        mc.BuildTriangle(b0, b1, t1);

        mc.BuildTriangle(b1, t2, t1);
        mc.BuildTriangle(b1, b2, t2);

        mc.BuildTriangle(b2, t3, t2);
        mc.BuildTriangle(b2, b3, t3);

        mc.BuildTriangle(b3, t0, t3);
        mc.BuildTriangle(b3, b0, t0);

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #22
0
    // Update is called once per frame
    void Update()
    {
        move = move + 0.01f;
        MeshFilter meshFilter = this.GetComponent <MeshFilter>();
        // one submesh for each face
        Vector3 center = new Vector3(0, 0, 0);

        mc.Clear(); // Clear internal lists and mesh

        for (int row = 0; row < 20; row++)
        {
            for (int col = 0; col < 20; col++)
            {
                // center.Set(col * size.x * (float)1.2, Perlin.Noise(col * size.x * (float)0.5f+move,row * size.z * (float)1f+move), row * size.z * (float)1.2);
                center.Set(col * size.x * (float)1.2, 0.25f * m_audioTest.clipRange(row, col), row * size.z * (float)1.2);

                CreateCube(center);
            }
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #23
0
파일: Game.cs 프로젝트: MarcStan/renderer
        protected override void Initialize()
        {
            Window.Title = "RenderTargetSample - Esc to quit";
            base.Initialize();
            IsMouseVisible  = true;
            IsFixedTimeStep = false;

            _pixel = new RenderTarget2D(GraphicsDevice, 1, 1);
            _pixel.SetData(new[] { Color.White });
            _renderContext = new DefaultRenderContext(_graphicsDeviceManager, Content);
            var builder = new TextureMeshDescriptionBuilder();

            builder.AddBox(new BoundingBox(Vector3.Zero, Vector3.One * 10), Vector2.One);
            var creator = new MeshCreator(GraphicsDevice);

            _mesh = creator.CreateMesh(builder);

            _camera = new StaticCamera(GraphicsDevice, Vector3.UnitZ * 50);

            _rt1 = CreateRenderTarget(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            _rt2 = CreateRenderTarget(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            _rt3 = CreateRenderTarget(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
        }
예제 #24
0
    // Update is called once per frame
    void Update()
    {
        loudness = this.GetComponent <AudioSourceLoudnessTester>().clipLoudness;
        // print(loudness);

        MeshFilter meshFilter = this.GetComponent <MeshFilter>();
        // one submesh for each face
        Vector3 center = new Vector3(0, 0, 0);

        mc.Clear(); // Clear internal lists and mesh

        for (int row = 0; row < 20; row++)
        {
            for (int col = 0; col < 20; col++)
            {
                float height = 1 + 0.9f * Perlin.Noise(col * size.x * (float)1.2, row * size.z * (float)1.2, loudness * 30);
                center.Set(col * size.x * (float)1.2, 0, row * size.z * (float)1.2);
                CreateCube(center, height);
            }
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #25
0
    // Use this for initialization
    void Start()
    {
        verts = new Vector3[size][];
        for (int i = 0; i < size; ++i)
        {
            verts[i] = new Vector3[size];
        }
        MeshCol = GetComponent <MeshCollider>();
        GenerateVerts();

        if (!UpdateOnTick)
        {
            MeshFilter  meshFilter = this.GetComponent <MeshFilter>();
            MeshCreator mc         = new MeshCreator();
            mc.bumpiness = bumpiness;

            GenerateMesh(mc);
            GenerateEnvironment();

            meshFilter.mesh    = mc.CreateMesh();
            MeshCol.sharedMesh = meshFilter.mesh;
        }
    }
        public override void Setup(Brush prevBrush, Brush nextBrush)
        {
            double aspect = Owner.ActualWidth / Owner.ActualHeight;

            GetNameScope().RegisterName("SlidingScreen", _slidingScreen);

            MeshGeometry3D mesh = MeshCreator.CreateMesh(SidePoints, SidePoints);

            mesh.Positions          = new RectangularMeshFiller().FillMesh(SidePoints, SidePoints, aspect);
            _slidingScreen.Geometry = mesh;

            // Back screen
            _screenRect = new Rectangle();

            // Assign brushes based on EffectType
            if (EffectType == GenieEffectType.IntoLamp)
            {
                _slidingScreen.Material = new DiffuseMaterial(prevBrush);
                _screenRect.Fill        = nextBrush;
            }
            else
            {
                _slidingScreen.Material = new DiffuseMaterial(nextBrush);
                _screenRect.Fill        = prevBrush;
            }

            // Camera
            PerspectiveCamera camera     = _viewport.Camera as PerspectiveCamera;
            double            angle      = camera.FieldOfView / 2;
            double            cameraZPos = (aspect / 2) / Math.Tan(angle * Math.PI / 180);

            camera.Position = new Point3D(0, 0, cameraZPos);

            Owner.AddTransitionElement(_screenRect);
            Owner.AddTransitionElement(_viewport);
        }
    // Update is called once per frame
    void Update()
    {
        mc.ListClear();
        //if (factor > 1) { inc = false; }
        //if (factor < -1) { inc = true; }
        /*if (inc) {*/
        factor   += Time.deltaTime * 0.4f;
        keyTimer += Time.deltaTime;
        //}
        //else if (!inc) { factor -= 0.005f; }
        for (int i = 0; i < 40; ++i)
        {
            for (int j = 0; j < 40; ++j)
            {
                cubeSize = size * 0.5f;
                key(i, j);
                if (!MusicOn)
                {
                    NoiseAnim(i, j);
                    this.GetComponent <AudioSource>().enabled = false;
                }
                if (MusicOn)
                {
                    this.GetComponent <AudioSource>().enabled = true;
                    SoundAnim(i, j);
                }

                // top of the cube
                // t0 is top left point
                Vector3 t0 = new Vector3(cubeSize.x + size.x * i * 1.2f, coordy, -cubeSize.z + size.z * j * 1.2f);
                Vector3 t1 = new Vector3(-cubeSize.x + size.x * i * 1.2f, coordy, -cubeSize.z + size.z * j * 1.2f);
                Vector3 t2 = new Vector3(-cubeSize.x + size.x * i * 1.2f, coordy, cubeSize.z + size.z * j * 1.2f);
                Vector3 t3 = new Vector3(cubeSize.x + size.x * i * 1.2f, coordy, cubeSize.z + size.z * j * 1.2f);
                // bottom of the cube
                Vector3 b0 = new Vector3(cubeSize.x + size.x * i * 1.2f, -cubeSize.y, -cubeSize.z + size.z * j * 1.2f);
                Vector3 b1 = new Vector3(-cubeSize.x + size.x * i * 1.2f, -cubeSize.y, -cubeSize.z + size.z * j * 1.2f);
                Vector3 b2 = new Vector3(-cubeSize.x + size.x * i * 1.2f, -cubeSize.y, cubeSize.z + size.z * j * 1.2f);
                Vector3 b3 = new Vector3(cubeSize.x + size.x * i * 1.2f, -cubeSize.y, cubeSize.z + size.z * j * 1.2f);
                //Debug.Log(t0);
                //Debug.Log(Perlin.Noise(t0));
                //Debug.Log(Perlin.Noise(100, 100, Random.Range(0, 1000) * 0.1f));

                // Top square
                mc.BuildTriangle(t0, t1, t2);
                mc.BuildTriangle(t0, t2, t3);
                // Bottom square
                mc.BuildTriangle(b2, b1, b0);
                mc.BuildTriangle(b3, b2, b0);
                // Back square
                mc.BuildTriangle(b0, t1, t0);
                mc.BuildTriangle(b0, b1, t1);
                mc.BuildTriangle(b1, t2, t1);
                mc.BuildTriangle(b1, b2, t2);
                mc.BuildTriangle(b2, t3, t2);
                mc.BuildTriangle(b2, b3, t3);
                mc.BuildTriangle(b3, t0, t3);
                mc.BuildTriangle(b3, b0, t0);
            }
        }

        if (coordy > 20f)
        {
            GameObject instR = Instantiate(ring, new Vector3(-50, coordy, 0), Quaternion.identity);
            Destroy(instR, 5f);
            if (coordy > 30f)
            {
                GameObject instF = Instantiate(firework, new Vector3(-50, coordy, 0), Quaternion.identity);
                Destroy(instF, 10f);
            }
        }
        meshFilter.mesh = mc.CreateMesh();
    }
    // Update is called once per frame
    void Update()
    {
        MeshFilter meshFilter = this.GetComponent <MeshFilter>();
        // one submesh for each face
        Vector3 center = new Vector3(0, 0, 0);

        mc.Clear(); // Clear internal lists and mesh

        //Inputs to increase and decrese grid numbers
        if (Input.GetKeyDown(KeyCode.Space))
        {
            gridCubes += 10;
        }

        if (Input.GetKeyDown(KeyCode.Backspace))
        {
            gridCubes -= 10;
        }

        //Inputs to increase and decrease the spacing between the cubes
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            distBetween -= 0.2;
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            distBetween += 0.2;
        }

        //Inputs for switching color
        if (Input.GetKeyDown(KeyCode.G))
        {
            //Alter the color
            altColor.g += 0.1f;
            //Assign the changed color to the material.
            rend.material.color = altColor;
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            //Alter the color
            altColor.r += 0.1f;
            //Assign the changed color to the material.
            rend.material.color = altColor;
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            //Alter the color
            altColor.b += 0.1f;
            //Assign the changed color to the material.
            rend.material.color = altColor;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            //Alter the color
            altColor.a += 0.1f;
            //Assign the changed color to the material.
            rend.material.color = altColor;
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            //Alter the color
            altColor.a += 0.1f;
            //Assign the changed color to the material.
            altColor            = orColor;
            rend.material.color = altColor;
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            partSpawn = true;
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            partSpawn = false;
        }

        //Creating the cubes grid
        for (int row = 0; row < gridCubes; row++)
        {
            for (int col = 0; col < gridCubes; col++)
            {
                center.Set(col * size.x * (float)distBetween, 0, row * size.z * (float)distBetween);
                CreateCube(center);
            }
        }

        meshFilter.mesh = mc.CreateMesh();
    }
예제 #29
0
        private void InitScene()
        {
            Scene = new Scene();

            var stallTexture     = new Texture("Resources/Textures/house.png");
            var stallTextureSnow = new Texture("Resources/Textures/checker.jpg");

            Shader = new Shader("Shaders/shader.vert", "Shaders/newShader.frag");
            var stallMaterial = new MaterialModel(Shader, new[] { stallTexture })
            {
                Ambient   = new Vector3(0.3f, 0.5f, 0.31f),
                Diffuse   = new Vector3(0.3f, 0.5f, 0.31f),
                Specular  = new Vector3(0.5f, 0.5f, 0.5f),
                Shininess = 32f
            };
            var stallMaterialSnow = new MaterialModel(Shader, new[] { stallTextureSnow })
            {
                Ambient   = new Vector3(0.3f, 0.5f, 0.31f),
                Diffuse   = new Vector3(0.3f, 0.5f, 0.31f),
                Specular  = new Vector3(0.5f, 0.5f, 0.5f),
                Shininess = 32f,
            };

            LampShader = new Shader("Shaders/shader.vert", "Shaders/lamp.frag");
            var cubeMat  = new ColorMaterial(LampShader, new Vector3(0f, 0f, 1f));
            var cubeMat2 = new ColorMaterial(LampShader, new Vector3(1f, 1f, 0f));

            var pointLight2      = new Light(LampShader, LightType.PointLight, new Vector3(1f, 1f, 0f) * 1.0f, new Vector3(1, 1, 1), 0.032f, 0.09f, 1);
            var pointLight       = new Light(LampShader, LightType.PointLight, new Vector3(0f, 0f, 1f) * 1.0f, new Vector3(1, 1, 1), 0.032f, 0.09f, 1);
            var directionalLight = new Light(LampShader, LightType.DirectionalLight, new Vector3(0.15f, 0.15f, 0.15f), new Vector3(1, 1, 1), 0.032f, 0.09f, 1);

            Camera = new Camera(Width / (float)Height, true, 3.5f, 3);

            Mesh meshCube   = MeshCreator.CreateMesh("Resources/cubeN.obj");
            Mesh meshGround = MeshCreator.CreateMesh("Resources/ground.obj");
            Mesh meshHouse  = MeshCreator.CreateMesh("Resources/houseTest.obj");
            Mesh meshStall  = MeshCreator.CreateMesh("Resources/stallTest.obj");

            GameObject cameraGameObject = new GameObject(new Transform(new Vector3(0, 2, 6), new Vector3(0, -90, 0), Vector3.One));

            cameraGameObject.AddComponent(Camera);
            cameraGameObject.AddComponent(new CameraMovement());

            GameObject pointLightGameObject = new GameObject(new Transform(new Vector3(2, 4f, 2), Vector3.Zero, new Vector3(0.5f, 0.5f, 0.5f)));

            pointLightGameObject.AddComponent(new MeshRenderer(meshCube, cubeMat));
            pointLightGameObject.AddComponent(new HouseMovement());
            pointLightGameObject.AddComponent(pointLight);

            GameObject pointLight2GameObject = new GameObject(new Transform(new Vector3(2, 4f, -2), Vector3.Zero, new Vector3(0.5f, 0.5f, 0.5f)));

            pointLight2GameObject.AddComponent(new MeshRenderer(meshCube, cubeMat2));
            //pointLight2GameObject.AddComponent(new HouseMovement());
            pointLight2GameObject.AddComponent(pointLight2);

            GameObject directionalLightGameObject = new GameObject(new Transform(Vector3.Zero, new Vector3(-5, 180, 0), Vector3.One));

            //directionalLightGameObject.AddComponent(new MeshRenderer(meshCube, cubeMat));
            directionalLightGameObject.AddComponent(directionalLight);

            GameObject groundGameObject = new GameObject();

            groundGameObject.AddComponent(new MeshRenderer(meshGround, stallMaterial));

            GameObject houseGameObject = new GameObject(new Transform(new Vector3(6, 0, 0), Vector3.Zero, Vector3.One));

            houseGameObject.AddComponent(new MeshRenderer(meshHouse, stallMaterial));

            GameObject house2GameObject = new GameObject(new Transform(new Vector3(15, 0, 0), new Vector3(0, 90, 0), Vector3.One));

            house2GameObject.AddComponent(new MeshRenderer(meshHouse, stallMaterialSnow));
            house2GameObject.AddComponent(new ChangeTextureScript());

            GameObject stallGameObject = new GameObject();

            stallGameObject.AddComponent(new MeshRenderer(meshStall, stallMaterial));

            GameObject stall2GameObject = new GameObject(new Transform(new Vector3(-4, 0, 0), new Vector3(0, 45, 0), Vector3.One));

            stall2GameObject.AddComponent(new MeshRenderer(meshStall, stallMaterial));



            Scene.AddGameObject(pointLightGameObject);
            Scene.AddGameObject(pointLight2GameObject);
            Scene.AddGameObject(groundGameObject);
            Scene.AddGameObject(houseGameObject);
            Scene.AddGameObject(house2GameObject);
            Scene.AddGameObject(stallGameObject);
            Scene.AddGameObject(stall2GameObject);
            Scene.AddGameObject(cameraGameObject);
            //Scene.AddGameObject(directionalLightGameObject);

            Scene.StartComponents();
        }
    // Update is called once per frame
    void Update()
    {
        float[] spectrum = new float[256];
        AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular);


        MeshFilter meshFilter = this.GetComponent <MeshFilter>();
        Mesh       mesh       = this.GetComponent <MeshFilter>().mesh;

        Vector3[] vertices = mesh.vertices;


        // one submesh for each face
        Vector3 center = new Vector3(0, 0, 0);

        mc.Clear(); // Clear internal lists and mesh

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            resize++;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow) && resize > 1.0f)
        {
            resize--;
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            distance += 0.1f;
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow) && distance > 1.2f)
        {
            distance -= 0.1f;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            for (int i = 0; i < vertices.Length; i++)
            {
                this.GetComponent <MeshRenderer>().material.color = Color.Lerp(Color.yellow, Color.blue, vertices[i].y);
            }
        }


        for (int j = 0; j < 20; j++)
        {
            for (int i = 0; i < 20; i++)
            {
                Vector3 cubeSize = size * 0.5f;
                //float timepass = 0;
                float timepass = Time.deltaTime * 20f;
                //timepass +=Time.deltaTime* 10.0f;

                float noisy = cubeSize.y + Perlin.Noise(cubeSize.x + size.x * i * 0.12f * spectrum[i] * 100.0f + timepass, 0, -cubeSize.z + size.z * j * 0.12f * spectrum[i] * 100.0f + timepass);
                //float noisy = cubeSize.y + Perlin.Noise(cubeSize.x + size.x * i * 0.12f + timepass, 0, -cubeSize.z + size.z * j * 0.12f + timepass);

                // top of the cube
                // t0 is top left point
                Vector3 t0 = new Vector3(cubeSize.x + size.x * i * distance, noisy * resize, -cubeSize.z + size.z * j * distance);
                Vector3 t1 = new Vector3(-cubeSize.x + size.x * i * distance, noisy * resize, -cubeSize.z + size.z * j * distance);
                Vector3 t2 = new Vector3(-cubeSize.x + size.x * i * distance, noisy * resize, cubeSize.z + size.z * j * distance);
                Vector3 t3 = new Vector3(cubeSize.x + size.x * i * distance, noisy * resize, cubeSize.z + size.z * j * distance);

                // bottom of the cube
                Vector3 b0 = new Vector3(cubeSize.x + size.x * i * distance, -cubeSize.y, -cubeSize.z + size.z * j * distance);
                Vector3 b1 = new Vector3(-cubeSize.x + size.x * i * distance, -cubeSize.y, -cubeSize.z + size.z * j * distance);
                Vector3 b2 = new Vector3(-cubeSize.x + size.x * i * distance, -cubeSize.y, cubeSize.z + size.z * j * distance);
                Vector3 b3 = new Vector3(cubeSize.x + size.x * i * distance, -cubeSize.y, cubeSize.z + size.z * j * distance);

                // Top square
                mc.BuildTriangle(t0, t1, t2);
                mc.BuildTriangle(t0, t2, t3);

                // Bottom square
                mc.BuildTriangle(b2, b1, b0);
                mc.BuildTriangle(b3, b2, b0);

                // Back square
                mc.BuildTriangle(b0, t1, t0);
                mc.BuildTriangle(b0, b1, t1);

                mc.BuildTriangle(b1, t2, t1);
                mc.BuildTriangle(b1, b2, t2);

                mc.BuildTriangle(b2, t3, t2);
                mc.BuildTriangle(b2, b3, t3);

                mc.BuildTriangle(b3, t0, t3);
                mc.BuildTriangle(b3, b0, t0);

                meshFilter.mesh = mc.CreateMesh();

                if (noisy > 1.1f)
                {
                    Instantiate(particlesystem, new Vector3(i * 2.0F, noisy * resize * 2, 0), Quaternion.identity);
                }
            }
        }
    }