天天看點

在Ventuz中配置Leapmotion環境

Ventuz版本6.4

Leapmotion版本3.2.0(可以從官網https://developer.leapmotion.com/releases/?category=orion上下載下傳)

1、解壓Leapmotion壓縮包,先安裝驅動

在Ventuz中配置Leapmotion環境

2、進入LeapSDK檔案夾,在lib檔案夾下找到LeapCSharp.NET3.5.dll檔案,通過gacutil.exe将LeapCSharp.NET3.5.dll添加到程式集緩存中去。(gacutil.exe檔案正常是找不到的,需要預設安裝Visual Studio後,在C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin路徑下能找到)

3、

a.右鍵電腦右下方開始按鈕,點選運作按鈕,在運作中輸入cmd,點選确認

在Ventuz中配置Leapmotion環境

b.在指令視窗輸入cd C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin,鍵盤按下Enter鍵;然後輸入gacutil -i "LeapCSharp.NET3.5.dll所在的路徑"

在Ventuz中配置Leapmotion環境

出現Assembly successfully added to the cache,表示添加成功。

重點提示!!!!!!:我的Leapmotion2.0硬體不支援Leapmotion SDK 3.0.0之前的SDK,請确認你的硬體是1.0還是2.0.

還有就是如果你下載下傳下來的SDK中沒有找到LeapCSharp.NET3.5.dll檔案,請下載下傳和我一樣的版本。

4、在LeapSDK\lib下,選擇X86或者X62(根據你的系統選擇)下的Leap.dll和LeapC.dll複制到你的Ventuz安裝根目錄下,就可以了。

5、下面是Ventuz下的C#腳本

using System;
using Ventuz.Kernel;
using System.Threading;
using Leap;
using System.EnterpriseServices.Internal;

public class Script : ScriptBase, System.IDisposable
{
	//Leap Motion Listener and controller
	SampleListener listener = new SampleListener ();
	Controller controller = new Controller();
	// This member is used by the Validate() method to indicate
	// whether the Generate() method should return true or false
	// during its next execution.
	private bool changed;
    
	// This Method is called if the component is loaded/created.
	public Script()
	{
		controller.Connect += listener.OnServiceConnect;
		controller.Device += listener.OnConnect;
		controller.FrameReady += listener.OnFrame;
	}
    
	// This Method is called if the component is unloaded/disposed
	public virtual void Dispose()
	{
		controller.Connect -= listener.OnServiceConnect;
		controller.Device -= listener.OnConnect;
		controller.FrameReady -= listener.OnFrame;
		controller.Dispose();
	}
    
	// This Method is called if an input property has changed its value
	public override void Validate()
	{
		// Remember: set changed to true if any of the output 
		// properties has been changed, see Generate()
	}
    
	// This Method is called every time before a frame is rendered.
	// Return value: if true, Ventuz will notify all nodes bound to this
	//               script node that one of the script's outputs has a
	//               new value and they therefore need to validate. For
	//               performance reasons, only return true if output
	//               values really have been changed.
	public override bool Generate()
	{
		if(listener.IsChanged)
		{
			CircleCCW();
		}else{
			
		}
		return false;
	}
}

//Sample Listener Class
public class SampleListener 
{
	public bool IsChanged;
	
	public void OnServiceConnect(object sender, ConnectionEventArgs args)
	{
		Console.WriteLine("Service Connected");
	}

	public void OnConnect(object sender, DeviceEventArgs args)
	{
		Console.WriteLine("Connected");
	}


	public void OnFrame(object sender, FrameEventArgs args)
	{
		// Get the most recent frame and report some basic information
		Frame frame = args.frame;
		if(frame.Hands.Count > 0){
			IsChanged = true;
		}
		else{
			IsChanged = false;
		}

	}
}
           

測試是可以用的,自己調這個花了三天時間,希望給剛接觸的人一點幫助。若有疑問郵箱聯系[email protected].

繼續閱讀