Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        int mapWidth  = 100;
        int mapHeight = 100;

        MapDisplay display = FindObjectOfType <MapDisplay>();
        MapGen     map     = FindObjectOfType <MapGen>();

        Vector2 offset = new Vector2(0, 0);
        int     seed   = Random.Range(-1000, 1000);

        float[,] noiseMap = Noise.GenerateNoiseMap(100, 100, map.noiseScale, 3, 0.2f, 3, seed, offset);

        Color[] colorMap = new Color[mapWidth * mapHeight];
        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < map.regions.Length; i++)
                {
                    if (currentHeight < map.regions[i].height)
                    {
                        colorMap[(y * mapWidth) + x] = map.regions[i].color;
                        break;
                    }
                }
            }
        }


        display.DrawMesh(MeshGen.TerrainMeshGen(noiseMap, map.heightMultiplier, map.meshHeightCurve),
                         ColorTexture.TextureColorMap(colorMap, mapWidth, mapHeight));
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Computes the pf image from histogram. Used for visualization.
        /// </summary>
        public void ComputePfImageFromHistogram()
        {
            float pf = 0;

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    int   idx   = i * Width + j;
                    Color pixel = ColorTexture.GetPixel(j, i);
                    pf = GetPf(pixel);
                    if (pf > 0.8f)
                    {
                        if (!ColorTextureVisual.GetPixel(j, i).Equals(Color.blue))   //&& Mask[idx] == defines.HIST_FG_PIXEL)
                        {
                            ColorTextureVisual.SetPixel(j, i, Color.Lerp(pixel, Color.green, 0.5f));

                            if (Mask[idx] == defines.HIST_FG_PIXEL)
                            {
                                ColorTextureVisual.SetPixel(j, i, Color.Lerp(pixel, Color.cyan, 0.5f));
                            }
                        }
                    }
                    else if (pf == 0.3f)
                    {
                        if (!ColorTextureVisual.GetPixel(j, i).Equals(Color.blue))
                        {
                            //ColorTextureVisual.SetPixel( j, i, Color.Lerp( pixel, Color.yellow, 0.2f ) );
                        }
                    }
                }
            }
            ColorTextureVisual.Apply();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets 3D points [units = meters] and calculated pf vector
        /// </summary>
        /// <param name="state">State.</param>
        private void PreparePointCloud(HoloProxies.Engine.trackerState state)
        {
            boundingbox = findBoundingBoxFromCurrentState(state);

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    int idx = i * Width + j;

                    // if point is not in the bounding box
                    if (j < boundingbox.x || j >= boundingbox.z || i < boundingbox.y || i >= boundingbox.w)
                    {
                        // mark as not useful
                        Camera3DPoints[idx].X = 0;
                        Camera3DPoints[idx].Y = 0;
                        Camera3DPoints[idx].Z = 0;
                        PfVec[idx]            = defines.OUTSIDE_BB;
                    }
                    else // if it's inside the box
                    {
                        Color pixel = ColorTexture.GetPixel(j, i);
                        PfVec[idx] = GetPf(pixel);
                        // Draw the bounding box region
                        if (drawBox && OnBoxEdge(j, i))
                        {
                            //ColorTextureVisual.SetPixel( j, i, Color.blue );
                            ColorTextureVisual.SetPixel(j, i, Color.Lerp(pixel, Color.blue, 0.3f));
                        }
                    }
                }
            } //end for
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of XyzAxis class.
 /// </summary>
 public XyzAxis()
 {
     Length = 1.0f;
     Radius = 0.025f;
     Signed = false;
     CoordinateSystemKind = CoordinateSystemKind.RightHanded;
     Texture = new ColorTexture(0.75f, 0.75f, 0.75f, 1.0f);
 }
 private void ReleaseTextures()
 {
     // Release the textures object.
     ColorTexture?.ShutDown();
     ColorTexture = null;
     NormalMapTexture?.ShutDown();
     NormalMapTexture = null;
 }
Ejemplo n.º 6
0
 private void ReleaseTextures()
 {
     // Release the normal map texture object.
     NormalMapTexture?.ShutDown();
     NormalMapTexture = null;
     // Release the color texture object.
     ColorTexture?.ShutDown();
     ColorTexture = null;
 }
Ejemplo n.º 7
0
    public ColorTexture ImportColorTexture(RawColorTexture rawTexture)
    {
        ColorTexture texture = new ColorTexture {
            image = ExtractImage(rawTexture.image, TextureProcessingType.Color),
            value = rawTexture.value
        };

        return(texture);
    }
Ejemplo n.º 8
0
 private void ShutdownBuffers()
 {
     // Release the Textures within this class.
     ColorTexture?.ShutDown();
     ColorTexture = null;
     NormalMapTexture?.ShutDown();
     NormalMapTexture = null;
     // Return the index buffer.
     IndexBuffer?.Dispose();
     IndexBuffer = null;
     // Release the vertex buffer.
     VertexBuffer?.Dispose();
     VertexBuffer = null;
 }
Ejemplo n.º 9
0
        public Map(int width, int height)
        {
            this.width  = width;
            this.height = height;
            _dirty      = true;
            _generating = false;

            coloredTextureCache   = ColorTexture.CreateRenderTarget(GraphicsDevice, width, height, true);
            intensityTextureCache = ColorTexture.CreateRenderTarget(GraphicsDevice, width, height, true);
            intensityTextureTemp  = ColorTexture.CreateRenderTarget(GraphicsDevice, width, height, true);
            intensityTexture      = ColorTexture.CreateRenderTarget(GraphicsDevice, width, height, true);

            colorMaps     = new List <Texture2D>();
            colorMapIndex = 0;
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        public void Dispose()
        {
            if (ColorTexture != null)
            {
                ColorTexture.Dispose();
            }

            if (DepthTexture != null)
            {
                DepthTexture.Dispose();
            }

            //if (FBOHandle != 0)
            //    TK.GL.Ext.DeleteFramebuffers(1, ref FBOHandle);

            GC.SuppressFinalize(this);
        }
Ejemplo n.º 11
0
        public void Dispose()
        {
            if (ID == 0)
            {
                return;
            }
            int id = ID;

            GL.DeleteFramebuffers(1, ref id);
            ColorTexture.Dispose();
            DepthTexture.Dispose();
            ID           = 0;
            Width        = 0;
            Height       = 0;
            ColorTexture = null;
            DepthTexture = null;
        }
Ejemplo n.º 12
0
    public void GenerateMap()
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, noiseScale, octaves,
                                                   persistence, lacunarity, seed, offset);

        Color[] colorMap = new Color[mapWidth * mapHeight];
        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight < regions[i].height)
                    {
                        colorMap[(y * mapWidth) + x] = regions[i].color;
                        break;
                    }
                }
            }
        }
        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(ColorTexture.TextureHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(ColorTexture.TextureColorMap(colorMap, mapWidth, mapHeight));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGen.TerrainMeshGen(noiseMap, heightMultiplier, meshHeightCurve),
                             ColorTexture.TextureColorMap(colorMap, mapWidth, mapHeight));
        }
    }
Ejemplo n.º 13
0
 /// <summary>
 /// Given a color space point with x,y coordinates of a pixel location
 /// return the corresponding rgb pixel
 /// </summary>
 /// <returns>The pixel value.</returns>
 /// <param name="pt">Point.</param>
 public Color GetPixelValue(ColorSpacePoint pt)
 {
     return(ColorTexture.GetPixel((int)pt.X, (int)pt.Y));
 }
 private static void SetColorTexture(TextureLoader textureLoader, ColorTexture colorTexture, out Vector3 value, out ShaderResourceView textureView)
 {
     value       = colorTexture.value;
     textureView = textureLoader.Load(colorTexture.image, TextureLoader.DefaultMode.Standard);
 }
Ejemplo n.º 15
0
        public Color Shade(HitRecord record, Vector3 wi)
        {
            Color   pixelColor = new Color(0, 0, 0);
            Vector3 normal     = record.SurfaceNormal;

            normal.Normalize();
            wi.Normalize();

            float noiseCoefficient = 0f;

            switch (Noise)
            {
            case Noise.Turbulence:
                noiseCoefficient = Turbulence(record.IntersectionPoint);
                break;

            case Noise.Marble:
                noiseCoefficient = Marble(record.IntersectionPoint);
                break;

            case Noise.Bumb:
                noiseCoefficient = 1f;
                normal           = Bump(record.IntersectionPoint, normal);
                break;

            case Noise.None:
                noiseCoefficient = 1f;
                break;

            default:
                noiseCoefficient = 1f;
                break;
            }

            if (BumpTexture != null)
            {
                Color   displacementColor  = BumpTexture.GetColorFromTexCoordinate(record.HitObject.GetTextudeCoordinates(record));
                Vector3 displacementNormal = normal;
                displacementNormal.X = ((displacementColor.R * 2) - 1);
                displacementNormal.Y = ((displacementColor.G * 2) - 1);
                displacementNormal.Z = displacementColor.B;
                normal = (Vector3.Dot(displacementNormal, normal) < 0) ? -displacementNormal : displacementNormal;
            }

            float nDotL = Vector3.Dot(normal, wi);

            if (nDotL > 0)
            {
                Color diffuse;

                if (Constants.TextureMapping && ColorTexture != null && !(record.HitObject is Plane))
                {
                    diffuse = ColorTexture.GetColorFromTexCoordinate(record.HitObject.GetTextudeCoordinates(record));
                }
                else
                {
                    diffuse = Diffuse;
                }

                //add Diffuse Light
                pixelColor.Append(diffuse.Mult(nDotL).Mult(noiseCoefficient));
                pixelColor.Append(pixelColor.Mult(1f - noiseCoefficient));
                //Calculate the Blinn halfVector
                Vector3 h = wi;
                h = Vector3.Add(h, wi);
                h.Normalize();


                float hDotN = Vector3.Dot(h, normal);
                if (hDotN > 0)
                {
                    float pow = (float)Math.Pow(hDotN, Shininess);
                    pixelColor.Append(Specular.Mult(pow));
                }
            }
            pixelColor.Append(Ambient);
            pixelColor.Clamp(0f, 1f);
            return(pixelColor);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Updates the frame by grabbing the rgb and depth from the Kinnect.
        /// </summary>
        /// <returns><c>true</c>, if frame was successfully updated, <c>false</c> otherwise.</returns>
        /// <param name="state">State.</param>
        public bool UpdateFrame(HoloProxies.Engine.trackerState state)
        {
            bool success = false;

            if (_Reader != null)
            {
                var frame = _Reader.AcquireLatestFrame();
                if (frame != null)
                {
                    //Debug.Log( "in here1" );
                    var colorFrame = frame.ColorFrameReference.AcquireFrame();
                    if (colorFrame != null)
                    {
                        //Debug.Log( "in here2" );
                        var depthFrame = frame.DepthFrameReference.AcquireFrame();
                        if (depthFrame != null)
                        {
                            //Debug.Log( "in here3" );
                            // get color data + texture
                            colorFrame.CopyConvertedFrameDataToArray(ColorData_full, ColorImageFormat.Rgba);

                            // get depth data
                            depthFrame.CopyFrameDataToArray(DepthData_full);

                            // Create a depth texture
                            //int index = 0;
                            //foreach (var ir in DepthData_full)
                            //{
                            //    byte intensity = (byte)(ir >> 8);
                            //    DepthRaw[index++] = intensity;
                            //    DepthRaw[index++] = intensity;
                            //    DepthRaw[index++] = intensity;
                            //    DepthRaw[index++] = 255; // Alpha
                            //}
                            //DepthTexture_full.LoadRawTextureData( DepthRaw );
                            //DepthTexture_full.Apply(); TODO fix this

                            // dispose frame
                            depthFrame.Dispose();
                            depthFrame = null;

                            // Map depth to RGBD
                            AlignRGBD();

                            // Unproject to 3D points in camera space (based on bounding box)
                            UnprojectFrom2Dto3D();

                            // Downsample all data frames if necessary
                            DownsampleAndFilterRGBDImage();

                            // Apply downsampled texture
                            ColorTexture.LoadRawTextureData(ColorData);
                            ColorTextureVisual.LoadRawTextureData(ColorData);

                            // Unproject points to 3D space
                            PreparePointCloud(state);

                            if (plotHistogram)
                            {
                                for (int i = 0; i < HistogramTexture.height; i++)
                                {
                                    for (int j = 0; j < HistogramTexture.width; j++)
                                    {
                                        int idx = i * HistogramTexture.width + j;
                                        HistogramTexture.SetPixel(j, i, new Color(histogram.posterior[idx * 256], 0, 0));
                                    }
                                }
                                HistogramTexture.Apply();
                            }

                            success = true;
                        }
                        colorFrame.Dispose();
                        colorFrame = null;
                    }
                    frame = null;
                }
            }
            return(success);
        }
Ejemplo n.º 17
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            WorldSpace.AddDrawableGroup(new ControllerDrawableGroup(1, "Controller", RenderContext));
            KeyPreview = true;
            KinectDeviceManager dev = null;

            //BasicGrid grid=new BasicGrid();
            //grid.Load(RenderContext);
            Controller = new TransformController(RenderContext, ScreenContext.HitChekcer);
            WorldSpace.AddResource(Controller, "Controller");
            //if (!String.IsNullOrEmpty(Settings.Default.InitLoadModel))
            //{
            //    MMDModel model = MMDModelWithPhysics.OpenLoad(Settings.Default.InitLoadModel, RenderContext);
            //    WorldSpace.AddResource(model);
            //    if (!String.IsNullOrEmpty(Settings.Default.InitLoadMotion))
            //    {
            //        model.MotionManager.ApplyMotion(model.MotionManager.AddMotionFromFile(Settings.Default.InitLoadMotion, false));
            //    }
            //}
            //更新する必要のあるワールドスペースは、UpdateRequireWorldsに追加しなけれbなりません。
            //PlaneBoard bill = new PlaneBoard(RenderContext, resourceView, new Vector2(800, 800));
            //WorldSpace.AddResource(bill);
            //bill.Transformer.Position = new Vector3(0, 0, 20);
            #region Kinectテストコード

#if KINECT
            OpenNIManager.Initialize();
            dev = OpenNIManager.getDevice();

            ColTexture = new ColorTexture(RenderContext, dev);
            tex2       = new DepthTexture(RenderContext, 1000, dev);
#endif

            #endregion

            //format = SpriteBatch.CreateTextformat("Meiriyo", 30, FontWeight.ExtraBold);


            //brush = SpriteBatch.CreateRadialGradientBrush(g,
            //    new RadialGradientBrushProperties() {CenterPoint = new PointF(100,100),GradientOriginOffset = new PointF(0,0),HorizontalRadius = 100f,VerticalRadius = 200f}).Brush;
            //brush = SpriteBatch.CreateSolidColorBrush(Color.Aquamarine);
            ScreenContext.CameraMotionProvider = new BasicCameraControllerMotionProvider(this, this);
            BasicGrid gird = new BasicGrid();
            gird.Visibility = true;
            gird.Load(RenderContext);

            ScreenContext.WorldSpace.AddResource(gird);
            //textureの世界には、childウィンドウに追加からできるようにしてあります。
            ControlForm controlForm = new ControlForm(RenderContext, ScreenContext, null, dev);
            controlForm.Show(this);

            //OpenFileDialog ofd = new OpenFileDialog();
            //if (ofd.ShowDialog() == DialogResult.OK)
            //{
            //    VMDCameraMotionProvider camMotion=VMDCameraMotionProvider.OpenFile(ofd.FileName);
            //    ScreenContext.CameraMotionProvider = camMotion;
            //    camMotion.Start();
            //}


            #region Kinectテストコード
#if KINECT
            PlaneBoard bill = new PlaneBoard(RenderContext, ColTexture.TextureResourceView);
            bill.Transformer.Position = new Vector3(0, 0, 50);
            //bill.Transformer.Rotation *= Quaternion.RotationAxis(new Vector3(0,1,0),(float) (Math.PI));
            form.WorldSpace.AddResource(bill);
            form.WorldSpace.AddDynamicTexture(ColTexture);
#endif

            #endregion
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Given a color space point with x,y coordinates of a pixel location
 /// set the corresponding pixel to the given color
 /// </summary>
 /// <param name="pt">Point.</param>
 public void SetPixelValue(ColorSpacePoint pt, Color color)
 {
     ColorTexture.SetPixel((int)pt.X, (int)pt.Y, color);
 }