Beispiel #1
0
    protected override void DerivedDraw(MotionEditor editor)
    {
        DepthMap sensor = GetDepthMap(editor.GetCurrentFrame(), editor.Mirror);

        sensor.Draw();
        if (ShowImage)
        {
            UltiDraw.Begin();
            UltiDraw.DrawGUIRectangle(Vector2.one / 2f, Vector2.one, UltiDraw.Mustard);
            Vector2 size = new Vector2(0.5f, 0.5f * Screen.width / Screen.height);
            for (int x = 0; x < sensor.GetResolution(); x++)
            {
                for (int y = 0; y < sensor.GetResolution(); y++)
                {
                    float distance  = Vector3.Distance(sensor.Points[sensor.GridToArray(x, y)], sensor.Pivot.GetPosition());
                    float intensity = 1f - distance / sensor.GetDistance();
                    UltiDraw.DrawGUIRectangle(
                        Vector2.one / 2f - size / 2f + new Vector2((float)x * size.x,
                                                                   (float)y * size.y) / (sensor.GetResolution() - 1),
                        size / (sensor.GetResolution() - 1),
                        Color.Lerp(Color.black, Color.white, intensity)
                        );
                }
            }
            UltiDraw.End();
        }
    }
Beispiel #2
0
    public MotionState(MotionData.Frame frame, bool mirrored)
    {
        Index               = frame.Index;
        Timestamp           = frame.Timestamp;
        Mirrored            = mirrored;
        Root                = frame.GetRootTransformation(mirrored);
        RootMotion          = frame.GetRootMotion(mirrored);
        BoneTransformations = frame.GetBoneTransformations(mirrored);
        BoneVelocities      = frame.GetBoneVelocities(mirrored);
        Trajectory          = frame.GetTrajectory(mirrored);
        HeightMap           = frame.GetHeightMap(mirrored);
        DepthMap            = frame.GetDepthMap(mirrored);

        PastBoneTransformations = new List <Matrix4x4[]>(6);
        PastBoneVelocities      = new List <Vector3[]>(6);
        for (int i = 0; i < 6; i++)
        {
            MotionData.Frame previous = frame.Data.GetFrame(Mathf.Clamp(frame.Timestamp - 1f + (float)i / 6f, 0f, frame.Data.GetTotalTime()));
            PastBoneTransformations.Add(previous.GetBoneTransformations(mirrored));
            PastBoneVelocities.Add(previous.GetBoneVelocities(mirrored));
        }

        FutureBoneTransformations = new List <Matrix4x4[]>(5);
        FutureBoneVelocities      = new List <Vector3[]>(5);
        for (int i = 1; i <= 5; i++)
        {
            MotionData.Frame future = frame.Data.GetFrame(Mathf.Clamp(frame.Timestamp + (float)i / 5f, 0f, frame.Data.GetTotalTime()));
            FutureBoneTransformations.Add(future.GetBoneTransformations(mirrored));
            FutureBoneVelocities.Add(future.GetBoneVelocities(mirrored));
        }
    }
Beispiel #3
0
    public DepthMap GetDepthMap(Frame frame, bool mirrored)
    {
        DepthMap  sensor = new DepthMap(Resolution, Size, Distance);
        Matrix4x4 pivot  = frame.GetBoneTransformation(Sensor, mirrored);

        pivot *= Matrix4x4.TRS(Vector3.zero, Quaternion.FromToRotation(Vector3.forward, Axis.GetAxis()), Vector3.one);
        sensor.Sense(pivot, Mask);
        return(sensor);
    }
        public DepthMap GetDepthMap(bool mirrored)
        {
            DepthMap  depthMap = new DepthMap();
            Matrix4x4 pivot    = GetBoneTransformation(Data.DepthMapSensor, mirrored);

            pivot *= Matrix4x4.TRS(Vector3.zero, Quaternion.FromToRotation(Vector3.forward, Data.GetAxis(Data.DepthMapAxis)), Vector3.one);
            depthMap.Sense(pivot, Data.ObjectMask);
            return(depthMap);
        }
Beispiel #5
0
        public Picture RenderSceneWithCamera(Scene scene, PerspectiveCamera camera)
        {
            var depth = new DepthMap(camera.Resolution);

            foreach (var pixelRay in camera.GetPixelRays())
            {
                depth[pixelRay.Position.X, pixelRay.Position.Y] = GetDepth(scene, pixelRay.Ray);
            }
            return(DepthAsPicture(depth));
        }
Beispiel #6
0
        private Picture DepthAsPicture(DepthMap depth)
        {
            var maxDepth = float.MinValue;
            var minDepth = float.MaxValue;

            for (var x = 0; x < depth.Width; x++)
            {
                for (var y = 0; y < depth.Height; y++)
                {
                    if (depth[x, y] == null)
                    {
                        continue;
                    }

                    var currentDepth = depth[x, y].Value;
                    if (currentDepth > maxDepth)
                    {
                        maxDepth = currentDepth;
                    }
                    if (currentDepth < minDepth)
                    {
                        minDepth = currentDepth;
                    }
                }
            }

            var picture = new Picture(depth.Resolution);

            for (var x = 0; x < depth.Width; x++)
            {
                for (var y = 0; y < depth.Height; y++)
                {
                    var intensity = GetIntensity(depth[x, y], minDepth, maxDepth);
                    var color     = new RgbColor {
                        Red = intensity, Green = intensity, Blue = intensity
                    };
                    picture.SetColor(x, y, color);
                }
            }
            return(picture);
        }
Beispiel #7
0
        internal void Initialize()
        {
            primaryRaysMap    = new RaysMap();
            allRaysMap        = new RaysMap();
            depthMap          = new DepthMap();
            normalMapRelative = new NormalMap(relative: true);
            normalMapAbsolute = new NormalMap(relative: false);

            normalMapAbsolute.mapArray             = normalMapRelative.mapArray;
            normalMapAbsolute.intersectionMapArray = normalMapRelative.intersectionMapArray;

            allMaps = new List <IMap> ();

            foreach (FieldInfo fieldInfo in typeof(AdditionalViews).GetFields())
            {
                if (typeof(IMap).IsAssignableFrom(fieldInfo.FieldType))
                {
                    allMaps.Add((IMap)fieldInfo.GetValue(singleton));
                }
            }
        }
Beispiel #8
0
        public bool Init(RenderingScene renderingScene)
        {
            _scene = renderingScene;

            var _device = Engine.I.Device;

            try
            {
                foreach (var ent in renderingScene.RenderableEntities)
                {
                    _device.LoadMesh(ent.Value.Mesh);
                    _device.LoadShader(ent.Value.Material.Shader);

                    if (ent.Value.Material.HasDiffuse)
                    {
                        _device.LoadTexture(ent.Value.Material.Diffuse);
                    }

                    if (ent.Value.Material.HasNormal)
                    {
                        _device.LoadTexture(ent.Value.Material.Normal);
                    }
                }
                _depthMap    = new DepthMap(renderingScene);
                _directLight = new DirectLightCaster(pos: new Vec3(90, 90, -150), dir: Vec3.Zero, color: new Vec3(234.0f / 255.0f, 215.0f / 255.0f, 213.0f / 255.0f));
                _depthMap.FillDepthMap(_directLight.LightSpaceMatrix);

                _shaderProgram = DepthMap.LoadSpecificShader("shadow&light");
                return(true);
            }
            catch (Exception e)
            {
#if DEBUG
                throw;
#endif
                RenderAPI.I.Core.Log.Error("Can't initialize diffuse stage.", e);
            }
            return(false);
        }
Beispiel #9
0
        public void Test()
        {
            var tracer = new ContourTracer();

            var map = new DepthMap(10, 10);

            map[6, 6] = 100;
            map[5, 5] = 100;
            map[6, 5] = 100;
            map[4, 5] = 100;
            map[3, 5] = 100;
            map[4, 4] = 100;
            map[5, 4] = 100;
            map[6, 4] = 100;
            map[4, 3] = 100;
            map[5, 3] = 100;
            map[6, 3] = 100;
            map[5, 2] = 100;

            var result = tracer.GetContourPoints(map);

            Assert.IsTrue(!result.Contains(new Point(5, 4, 100)));
        }
Beispiel #10
0
 public void Dispose()
 {
     GL.DeleteFramebuffer(FrameBufferObjectHandle); MyGL.Check();
     DepthMap.Dispose();
 }