Coder Social home page Coder Social logo

playcanvas-ar's Introduction

PlayCanvasAR - Fast and Easy AR for the Web

PlayCanvasAR makes it easy to build lightning fast augmented reality applications. With it, you can construct web-based AR applications with zero programming using the PlayCanvas Editor. Just drag in your 3D models and watch them appear in AR!

PlayCanvas Editor

But if you want to create something more interactive, you can call on the full power of the PlayCanvas scripting API.

Demo

Before you begin, print out the following markers: Hiro and Kanji.

Now click here for a demonstration. We recommend running it on mobile. If you use iOS, you'll need to ensure you have upgraded to iOS 11, which is required to access the camera from Safari.

Or check out a little video:

YouTube video

Features

  • Amazing Performance - PlayCanvasAR delivers 60 frames per second, even on mobile.
  • Marker-based Tracking - PlayCanvasAR utilizes the amazing ARToolkit, an open source marker-based tracking library. Originally coded in C++, it has been ported to JavaScript using Emscripten.
  • Incredible Visuals - PlayCanvas provides an advanced WebGL graphics engine. It supports the latest WebGL 2 graphics API and implements Physically Based Rendering to achieve incredible visuals for your AR applications. And yes, that's open sourced too.

Getting Started with PlayCanvasAR

  1. Create an account on playcanvas.com (if you haven't already).
  2. Fork the AR Starter Kit project (which contains the latest version of playcanvas-ar.js).
  3. Hit the launch button and see AR in action (we recommend using your mobile device!).

Configuring PlayCanvasAR in the Editor

The playcanvas-ar.js script contains two script objects: arCamera and arMarker. The arCamera script renders a device's camera feed and tracks the feed image for AR markers. It can be added to an entity that has a camera component. The interface generated is as follows:

PlayCanvas Editor

To create a new marker entity, simply add a script component and add the arMarker script. This will generate the following UI:

PlayCanvas Editor

Scripting with PlayCanvasAR

The PlayCanvas Editor allows you to build your AR apps visually. But you may want to create AR powered entities programmatically. Or you may want to build AR apps by simply using the PlayCanvas Engine without the Editor. PlayCanvas AR exposes two script objects: 'arCamera' and 'arMarker'. 'Engine-only' scripting examples can be found in the examples folder.

arCamera

This code creates an AR-enabled camera:

var camera = new pc.Entity("AR Camera");
camera.addComponent("camera", {
    clearColor: new pc.Color(0, 0, 0, 0)
});
camera.addComponent("script");
camera.script.create("arCamera", {
    attributes: {
        cameraCalibration: asset,
        detectionMode: 0,     // Color Template
        matrixCodeType: 0,    // 3x3
        labelingMode: 1,      // Black Region
        processingMode: 0,    // Frame
        thresholdMode: 0,     // Manual
        threshold: 100,
        trackerResolution: 0, // Full
        trackAlternateFrames: false,
        debugOverlay: false,
        videoTexture: false
    }
});
app.root.addChild(camera);
Attribute Type Description
cameraCalibration pc.Asset Data file containing the calibration properties for the camera to be used.
detectionMode Number The pattern detection determines the method by which ARToolKit matches detected squares in the video image to marker templates and/or IDs. ARToolKit can match against pictorial "template" markers, whose pattern files are created with the mk_patt utility, in either colour or mono, and additionally can match against 2D-barcode-type "matrix" markers, which have an embedded marker ID. Two different two-pass modes are also available, in which a matrix-detection pass is made first, followed by a template-matching pass. Defaults to 0 (Color Template).
matrixCodeType Number Set the size and ECC algorithm to be used for matrix code (2D barcode) marker detection. When matrix-code (2D barcode) marker detection is enabled (see Detection Mode) then the size of the barcode pattern and the type of error checking and correction (ECC) with which the markers were produced can be set via this function. This setting is global to a given AR Camera; It is not possible to have two different matrix code types in use at once. Defaults to 0 (3x3).
labelingMode Number Select between detection of black markers and white markers.\n\nARToolKit's labelling algorithm can work with both black-bordered markers on a white background ('Black Region') or white-bordered markers on a black background ('White Region'). This property allows you to specify the type of markers to look for. Note that this does not affect the pattern-detection algorithm which works on the interior of the marker.
processingMode Number When the image processing mode is 'Frame', ARToolKit processes all pixels in each incoming image to locate markers. When the mode is 'Field', ARToolKit processes pixels in only every second pixel row and column. This is useful both for handling images from interlaced video sources (where alternate lines are assembled from alternate fields and thus have one field time-difference, resulting in a 'comb' effect) such as Digital Video cameras. The effective reduction by 75% in the pixels processed also has utility in accelerating tracking by effectively reducing the image size to one quarter size, at the cost of pose accuracy.
thresholdMode Number The thresholding mode to use. The standard ARToolKit options are available: Manual (0), Median (1), Otsu (2), Adaptive (3). Defaults to 0 (Manual).
threshold Number The binarization threshold is an 8-bit number that is in the range [0, 255], inclusive. The default value is 100, allowing ARToolKit to easily find markers in images that have good contrast. This value is only used when the mode is set to Manual. Defaults to 100.
trackerResolution Number Controls the resolution of the tracker image. Each video frame is copied to the tracker image for marker detection. Reducing the tracker image resolution will speed up marker detection but will also make it less precise. For example, a video camera source may have a resolution of 640x480. The tracker image will have the following resolutions based on the selected option: 'Full': 640x480, 'Three Quarters': 480x360, 'Half': 320x240, 'Quarter': 160x120.
trackAlternateFrames Boolean If selected, tracking is only performed on every other update. This can increase lag in tracking but will reduce CPU load.
debugOverlay Boolean Enables or disables the debug overlay. When enabled, a black and white debug image is generated during marker detection. The debug image is useful for visualizing the binarization process and choosing a threshold value. The image is displayed as an overlay on top of the 3D scene.
videoTexture Boolean Streams the camera feed to a video texture if enabled. Otherwise, a video DOM element is used. Defaults to false.

arMarker

This code creates an AR marker entity:

var hiro = new pc.Entity("Hiro Marker");
hiro.addComponent("script");
hiro.script.create("arMarker", {
    attributes: {
        pattern: asset,
        matrixId: 0,
        width: 1,
        deactivationTime: 0.25,
        shadow: true,
        shadowStrength: 0.5
    }
});
app.root.addChild(hiro);
Attribute Type Description
pattern pc.Asset The marker pattern to track. This can be the Hiro or Kanji markers or a marker you have generated yourself.
matrixId Number The matrix ID. If no pattern template is set, the marker is a matrix. Defaults to 0.
width Number The width of the marker. Defaults to 1.
deactivationTime Number The time in seconds from when a marker is lost before its children are deactivated. Defaults to 0.25.
shadow Boolean Enable this option to generate shadows in the plane of the marker that blend with the camera feed. Defaults to true.
shadowStrength Number Control the strength of the shadow. 1 is full strength and 0 is disabled. Defaults to 0.5.

Supported Operating Systems and Browsers

  • Android 4.0+ (Chrome 21+)
  • iOS 11+ (Safari 11+, Chrome 21+, Firefox 17+)
  • Windows XP+ (Chrome 21+, Firefox 17+, Opera 18+, Edge 12+)
  • macOS (Safari 11+, Chrome 21+, Firefox 17+, Opera 18+)
  • Linux (Chrome 21+, Firefox 17+, Opera 18+)

Join the fun!

AR is fun, so why not get involved? Find a bug? Need a feature? Want to contribute something? Add an issue!

playcanvas-ar's People

Contributors

willeastcott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

playcanvas-ar's Issues

How to get front facing camera?

I note that under constraints, it uses facingmode: "environtment" for the rear camera. What is the string i would need to use the front facing camera instead for mobile devices?

Creating new markers...

Hello,
I'm looking at the only available example and currently trying to replicate it with a new marker.
The getting started section explains how to create a new arMarker in the editor but not how to make the entity spawn.
I've created my pattern , uploaded in the folder playcanvas-ar/artoolkit/pattern/pattern, dragged the asset in the Pattern filename, then I draged in the editor the BlueBox as a children of my new Marker (I've taken it from the Matrix Marker that I still don't understand what is it used for). When I launch on mobile I can see the orange box for the Hiro pattern but not the blue one for mine.
I don't know if simply making the blue box a child of my marker would actually make it work, it seems I'm missing a piece of configuration but I don't see any additional scripts besides playcanvas-ar.js.

Is it possible to trigger an animation, a sound or something else?

Tracking Not Stable

Hi,

The tracking is not really stable after doing a quick test of the sample project.

I'm using Samsung S20 Ultra which is a really powerful and recent phone.

Here's the video of my test:
https://youtube.com/shorts/0ekF6gc3P3U?feature=share

The object does always follow the tracked image it seems like. As I move the tracked image, the cube rotate weirdly around the image.

Also, is there a specific size that the image needs to be printed out? It's not mentionned in the documentation, at least that I saw. Usually you need a specific physical size. Maybe that's why the tracking is poor in my case. What would be the physical size for printed image?

Also, only the Hiro image seems to be working using the sample. Am I missing anything?

Thank you!

Not working on Android

Currently having an issue getting the camera to work on Android devices. The play canvas app launches and then just shows a grey/blue screen. This is also reproducible in the demo example you provided.

I tried adding a UI to see if the app wasn't launching at all but I could see it. So it looks like an issue with init/rendering the camera from the device?

I'll test IOS when I get the chance.

I tried looking around in the source to see if I could identify the problem, but no luck.
Just moved to PlayCanvas from Unity, Loving working with AR so far. Fun and easy to play around with.

Any help would be appreciated.
Thanks.

How To Use Natural Feature Tracking (NFT) to Recognize and Track an Image?

This project is very interesting.
But use 2D-Barcode Markers is not cool,i tired use NFT markers,just get error~

abort() at Error
at jsStackTrace (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:1:41099)
at stackTrace (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:1:41282)
at Object.abort (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:18:4866)
at _abort (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:1:106287)
at Vj (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:8:84243)
at Ee (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:9:3399)
at De (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:10:81100)
at je (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:10:64428)
at de (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:10:52972)
at Array.wg (https://launch.playcanvas.com/api/assets/files/playcanvas-ar/artoolkit/artoolkit.min.js?id=10202190:9:85893)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

I'm just starting to use it,not too skilled.
any idea? or do i need to use a special API?Or any reference?

How To Make Folder For JSArtoolkit Get Files?

Hi,
I submitted a Issues a few days ago,was about NFT.
So I looked at the relevant information and got a solution,someone use the JSArtoolkit NTF branch to implement NTF.
I tried to use it locally, but I can't use it in playcanvas,because can't get the file URL right when you get it.

artoolkit.api.js whats written like this

ARController.prototype.loadNFTMarker = function(markerURL, onSuccess, onError) {
		var self = this;
		return artoolkit.addNFTMarker(this.id, markerURL, function(id) {
			self.nftMarkerCount = id + 1;
			onSuccess(id);
		}, onError);
	};

function addNFTMarker(arId, url, callback) {
		var mId = marker_count++;
		var prefix = '/markerNFT_' + mId;
		var filename1 = prefix + '.fset';
		var filename2 = prefix + '.iset';
		var filename3 = prefix + '.fset3';
		ajax(url + '.fset', filename1, function() {
			ajax(url + '.iset', filename2, function() {
				ajax(url + '.fset3', filename3, function() {
					var id = Module._addNFTMarker(arId, prefix);
					if (callback) callback(id);
				});
			});
		});
	}

If this URL is locally, is no problem,but use playcanvase getFileUrl() function,get URL like "URL?di=XXXX=XXX" fromat.

Artoolkit api cant use this URL combination right file URL,cant get NFT files.
Maybe it's not a problem now, but if you want to use it in the future, it should be met, so can you help me to see how to solve this problem?
Finally, my English is bad. I can read it, but I am not sure whether the expression is accurate or correct. Please not mind

How to scale down the camera captured stream?

I am using Playcanvas and want to capture the view of a real camera to put into my VR application.
As far as I know, there is no built-in device camera example in Playcanvas.
So, the only solution I know is using your ported scripts to have my camera integrated.
However, the injected camera stream is now consuming the whole tab region of my browser (Video texture mode: enabled).
I just wonder that is there any way to bound the captured video stream within certain window, such as a "$px by $px" window?

Thank you,
Kien

Add a portal-style example

Demonstrate how to achieve a portal type effect, where a marker acts like a window into another world/dimension.

Barcode patterns

Hi there, great project! Wondering if this will work with 3X3 Barcode patterns? Thanks!

Unable to use kanji marker

Hi,

Thanks for the lib. I'm quite new to the AR world.

I would like to ask a question about how to change the marker into kanji marker.

I have done the following steps :

  1. In the AR Camera, I have already add the arMarker at the script sub menu.
  2. Set the pattern into kanji.patt
  3. Build
  4. Publish the project

But i still failed to show an object using kanji marker. Is there any missing steps that i haven't done before?

Thanks for ur help.

Regards,

Han

Add support for multi-markers

Add support for multi-markers - both barcode/matrix type and standard pattern type.

Need to determine how multi-markers are specified. Options are:

  1. The standard .dat format outlined in the ARToolkit5 SDK.
  2. Set up sub-markers manually by specifying them in the Editor (or via the API).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.