コード例 #1
0
ファイル: BoidManager.cs プロジェクト: lshoek/reef-unity
    void Start()
    {
        m_depthManager      = Application.Instance.KinectDepthManager;
        m_beatInfoManager   = Application.Instance.BeatInfoManager;
        m_videoPlaneManager = Application.Instance.VideoPlaneManager;
        m_dataAccessor      = Application.Instance.CreatureDataAccessor;

        settings = new BoidSettings();
        settings.obstacleMask = 1 << LayerMask.NameToLayer("Bounds") | 1 << LayerMask.NameToLayer("ColliderMesh");
        settings.layer        = Layer;

        videoPlayer                 = gameObject.AddComponent <VideoPlayer>();
        videoPlayer.isLooping       = true;
        videoPlayer.audioOutputMode = VideoAudioOutputMode.None;
        videoPlayer.renderMode      = VideoRenderMode.RenderTexture;
        videoPlayer.clip            = m_dataAccessor.GetRandomClip();

        RT = new RenderTexture(VIDEO_RT_RES, VIDEO_RT_RES, 0, RenderTextureFormat.ARGB32);
        videoPlayer.targetTexture = RT;
        videoPlayer.Play();

        boids = new Boid[NumBoids];
        for (int i = 0; i < NumBoids; i++)
        {
            GameObject ob = Instantiate(Resources.Load("Prefabs/Boid") as GameObject);
            ob.name = $"Boid{i}";
            ob.transform.SetParent(Application.Instance.WorldParent);
            boids[i] = ob.GetComponent <Boid>();
            boids[i].Init(settings);
        }
        computeShader = Resources.Load("ComputeShaders/Boids") as ComputeShader;
    }
コード例 #2
0
    void Start()
    {
        m_depthManager = Application.Instance.KinectDepthManager;
        m_frameManager = Application.Instance.KinectFrameManager;

        m_meshCollider = GetComponent <MeshCollider>();

        float depthAspect = m_frameManager.DepthWidthDownsampled / m_frameManager.DepthHeightDownsampled;

        transform.parent.localPosition = new Vector3(-ReefHelper.DisplayHeight * depthAspect / 2, ReefHelper.DisplayHeight / 2);

        m_depthManager.OnActivationChanged += (x) => { SetActive(x); };
    }
コード例 #3
0
    void Start()
    {
        m_frameManager = Application.Instance.KinectFrameManager;
        m_depthManager = Application.Instance.KinectDepthManager;

        m_pRenderer   = GetComponent <Renderer>();
        m_pMeshFilter = GetComponent <MeshFilter>();
        m_camera      = Application.Instance.MainCamera;

        m_pTextureMixMaterial = new Material(Resources.Load("Shaders/KinectDepthColorMixer") as Shader);
        m_pKinectDepthColorRT = new RenderTexture(m_frameManager.DepthFrameWidth, m_frameManager.DepthFrameHeight, 0, RenderTextureFormat.ARGB32);

        m_pColorToDepth = new Vector2[m_frameManager.DepthFrameWidth / m_pColorDownsampleSize * m_frameManager.DepthFrameHeight / m_pColorDownsampleSize];

        GameObject ob = GameObject.CreatePrimitive(PrimitiveType.Plane);

        ob.transform.SetParent(m_camera.transform);

        float depthAspect = m_frameManager.DepthWidthDownsampled / m_frameManager.DepthHeightDownsampled;

        m_pKinectVideoPlane = ob.AddComponent <VideoPlane>();
        m_pKinectVideoPlane.Init(Depth);
        m_pKinectVideoPlane.SetWidth(ReefHelper.DisplayHeight * depthAspect);
        m_pKinectVideoPlane.SetVideoTexture(m_pKinectDepthColorRT);

        m_pTextureMixMaterial.SetTexture("_ColorTex", m_frameManager.GetColorTexture());
        m_pTextureMixMaterial.SetTexture("_DepthTex", m_frameManager.GetDepthTexture());
        m_pTextureMixMaterial.SetFloat("_DownsampleSize", m_pColorDownsampleSize);

        ReleaseBuffers();

        DepthSpacePoint[] depthPoints = m_frameManager.GetDepthCoordinates();
        if (depthPoints != null)
        {
            m_pDepthComputeBuffer = new ComputeBuffer(m_frameManager.GetColorSpacePointBuffer().Length, sizeof(float) * 2);
            m_pTextureMixMaterial.SetBuffer("DepthCoords", m_pDepthComputeBuffer);
        }
        m_depthManager.OnActivationChanged += (x) => { SetActive(x); };
    }