Пример #1
0
        private bool CreateImageTargets()
        {
            int num = VuforiaWrapper.Instance.DataSetGetNumTrackableType((int)TypeMapping.GetTypeID(typeof(ImageTarget)), this.mDataSetPtr);

            if (num <= 0)
            {
                return(false);
            }
            IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ImageTargetData)) * num);

            if (VuforiaWrapper.Instance.DataSetGetTrackablesOfType((int)TypeMapping.GetTypeID(typeof(ImageTarget)), intPtr, num, this.mDataSetPtr) == 0)
            {
                Debug.LogError("Could not create Image Targets");
                return(false);
            }
            for (int i = 0; i < num; i++)
            {
                ImageTargetData imageTargetData = (ImageTargetData)Marshal.PtrToStructure(new IntPtr(intPtr.ToInt64() + (long)(i * Marshal.SizeOf(typeof(ImageTargetData)))), typeof(ImageTargetData));
                if (!this.mTrackablesDict.ContainsKey(imageTargetData.id))
                {
                    StringBuilder stringBuilder = new StringBuilder(128);
                    VuforiaWrapper.Instance.DataSetGetTrackableName(this.mDataSetPtr, imageTargetData.id, stringBuilder, 128);
                    ImageTarget value = new ImageTargetImpl(stringBuilder.ToString(), imageTargetData.id, ImageTargetType.PREDEFINED, this);
                    this.mTrackablesDict[imageTargetData.id] = value;
                }
            }
            Marshal.FreeHGlobal(intPtr);
            return(true);
        }
Пример #2
0
        public override DataSetTrackableBehaviour CreateTrackable(TrackableSource trackableSource, GameObject gameObject)
        {
            TrackableSourceImpl trackableSourceImpl = (TrackableSourceImpl)trackableSource;
            StringBuilder       stringBuilder       = new StringBuilder(128);
            IntPtr           intPtr           = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SimpleTargetData)));
            int              num              = VuforiaWrapper.Instance.DataSetCreateTrackable(this.mDataSetPtr, trackableSourceImpl.TrackableSourcePtr, stringBuilder, 128, intPtr);
            SimpleTargetData simpleTargetData = (SimpleTargetData)Marshal.PtrToStructure(intPtr, typeof(SimpleTargetData));

            Marshal.FreeHGlobal(intPtr);
            if (num == (int)TypeMapping.GetTypeID(typeof(ImageTarget)))
            {
                ImageTarget imageTarget = new ImageTargetImpl(stringBuilder.ToString(), simpleTargetData.id, ImageTargetType.USER_DEFINED, this);
                this.mTrackablesDict[simpleTargetData.id] = imageTarget;
                Debug.Log(string.Format("Trackable created: {0}, {1}", num, stringBuilder));
                return(((StateManagerImpl)TrackerManager.Instance.GetStateManager()).FindOrCreateImageTargetBehaviourForTrackable(imageTarget, gameObject, this));
            }
            Debug.LogError("DataSet.CreateTrackable returned unknown or incompatible trackable type!");
            return(null);
        }