@bezlepkin/nativescript-ar
Advanced tools
Comparing version
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARBox = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARBox = (function (_super) { | ||
__extends(ARBox, _super); | ||
function ARBox() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARBox extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, fragment) { | ||
return new Promise(async (resolve, reject) => { | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
const defaultMaterial = await arcommon_1.ARCommonNode.getDefaultMaterial(); | ||
const size = new com.google.ar.sceneform.math.Vector3(options.dimensions instanceof Object ? options.dimensions.x : options.dimensions, options.dimensions instanceof Object ? options.dimensions.y : options.dimensions, options.dimensions instanceof Object ? options.dimensions.z : options.dimensions); | ||
const center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
const renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeCube(size, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARBox(options, node)); | ||
}); | ||
} | ||
ARBox.create = function (options, fragment) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var node, defaultMaterial, size, center, renderable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
return [4, arcommon_1.ARCommonNode.getDefaultMaterial()]; | ||
case 1: | ||
defaultMaterial = _a.sent(); | ||
size = new com.google.ar.sceneform.math.Vector3(options.dimensions instanceof Object ? options.dimensions.x : options.dimensions, options.dimensions instanceof Object ? options.dimensions.y : options.dimensions, options.dimensions instanceof Object ? options.dimensions.z : options.dimensions); | ||
center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeCube(size, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARBox(options, node)); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
return ARBox; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
exports.ARBox = ARBox; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARCommonNode = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var ar_common_1 = require("../../ar-common"); | ||
var ARCommonNode = (function () { | ||
function ARCommonNode(options, node) { | ||
var _this = this; | ||
const core_1 = require("@nativescript/core"); | ||
const ar_common_1 = require("../../ar-common"); | ||
class ARCommonNode { | ||
constructor(options, node) { | ||
this.android = node; | ||
@@ -14,6 +13,6 @@ this.onTapHandler = options.onTap; | ||
if (!this.onTapHandler) { | ||
this.onTapHandler = (function (interaction) { return options.parentNode.onTap(interaction.touchPosition); }); | ||
this.onTapHandler = (interaction => options.parentNode.onTap(interaction.touchPosition)); | ||
} | ||
if (!this.onLongPressHandler) { | ||
this.onLongPressHandler = (function (interaction) { return options.parentNode.onLongPress(interaction.touchPosition); }); | ||
this.onLongPressHandler = (interaction => options.parentNode.onLongPress(interaction.touchPosition)); | ||
} | ||
@@ -35,6 +34,6 @@ } | ||
this.android.setOnTapListener(new com.google.ar.sceneform.Node.OnTapListener({ | ||
onTap: function (hitResult, motionEvent) { | ||
var duration = motionEvent.getEventTime() - motionEvent.getDownTime(); | ||
var nativePosition = _this.android.getLocalPosition(); | ||
_this.position = { | ||
onTap: (hitResult, motionEvent) => { | ||
const duration = motionEvent.getEventTime() - motionEvent.getDownTime(); | ||
const nativePosition = this.android.getLocalPosition(); | ||
this.position = { | ||
x: nativePosition.x, | ||
@@ -45,3 +44,3 @@ y: nativePosition.y, | ||
if (duration > 700) { | ||
_this.onLongPress({ | ||
this.onLongPress({ | ||
x: hitResult.getPoint().x, | ||
@@ -55,3 +54,3 @@ y: hitResult.getPoint().y | ||
} | ||
_this.onTap({ | ||
this.onTap({ | ||
x: hitResult.getPoint().x, | ||
@@ -64,3 +63,3 @@ y: hitResult.getPoint().y | ||
} | ||
ARCommonNode.createNode = function (options, fragment) { | ||
static createNode(options, fragment) { | ||
if (!ARCommonNode.camera) { | ||
@@ -73,13 +72,13 @@ ARCommonNode.camera = fragment.getArSceneView().getScene().getCamera(); | ||
return new com.google.ar.sceneform.Node(); | ||
}; | ||
ARCommonNode.prototype.moveTo = function (to) { | ||
var currentPosition = this.android.getLocalPosition(); | ||
} | ||
moveTo(to) { | ||
const currentPosition = this.android.getLocalPosition(); | ||
this.android.setLocalPosition(new com.google.ar.sceneform.math.Vector3(to.x !== undefined ? to.x : currentPosition.x, to.y !== undefined ? to.y : currentPosition.y, to.z !== undefined ? to.z : currentPosition.z)); | ||
}; | ||
ARCommonNode.prototype.moveBy = function (by) { | ||
var currentPosition = this.android.getLocalPosition(); | ||
} | ||
moveBy(by) { | ||
const currentPosition = this.android.getLocalPosition(); | ||
this.android.setLocalPosition(new com.google.ar.sceneform.math.Vector3(currentPosition.x + by.x, currentPosition.y + by.y, currentPosition.z + by.z)); | ||
}; | ||
ARCommonNode.prototype.getPosition = function () { | ||
var pos = this.android.getLocalPosition(); | ||
} | ||
getPosition() { | ||
const pos = this.android.getLocalPosition(); | ||
return { | ||
@@ -90,5 +89,5 @@ x: pos.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.getWorldPosition = function () { | ||
var pos = this.android.getWorldPosition(); | ||
} | ||
getWorldPosition() { | ||
const pos = this.android.getWorldPosition(); | ||
return { | ||
@@ -99,33 +98,33 @@ x: pos.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.setPosition = function (pos) { | ||
} | ||
setPosition(pos) { | ||
this.android.setLocalPosition(new com.google.ar.sceneform.math.Vector3(pos.x, pos.y, pos.z)); | ||
}; | ||
ARCommonNode.prototype.setWorldPosition = function (pos) { | ||
} | ||
setWorldPosition(pos) { | ||
this.android.setWorldPosition(new com.google.ar.sceneform.math.Vector3(pos.x, pos.y, pos.z)); | ||
}; | ||
ARCommonNode.prototype.getDistanceTo = function (otherPosition) { | ||
} | ||
getDistanceTo(otherPosition) { | ||
return 0; | ||
}; | ||
ARCommonNode.prototype.rotateBy = function (by) { | ||
var currentRotation = this.android.getLocalRotation(); | ||
var rotateBy = new com.google.ar.sceneform.math.Quaternion(new com.google.ar.sceneform.math.Vector3(by.x, by.y, by.z)); | ||
} | ||
rotateBy(by) { | ||
const currentRotation = this.android.getLocalRotation(); | ||
const rotateBy = new com.google.ar.sceneform.math.Quaternion(new com.google.ar.sceneform.math.Vector3(by.x, by.y, by.z)); | ||
this.android.setLocalRotation(com.google.ar.sceneform.math.Quaternion.multiply(currentRotation, rotateBy)); | ||
}; | ||
ARCommonNode.prototype.setRotation = function (rot) { | ||
} | ||
setRotation(rot) { | ||
this.android.setLocalRotation(new com.google.ar.sceneform.math.Quaternion(new com.google.ar.sceneform.math.Vector3(rot.x, rot.y, rot.z))); | ||
}; | ||
ARCommonNode.prototype.lookAtWorldPosition = function (worldPos) { | ||
var direction = com.google.ar.sceneform.math.Vector3.subtract(this.android.getWorldPosition(), new com.google.ar.sceneform.math.Vector3(worldPos.x, worldPos.y, worldPos.z)); | ||
} | ||
lookAtWorldPosition(worldPos) { | ||
const direction = com.google.ar.sceneform.math.Vector3.subtract(this.android.getWorldPosition(), new com.google.ar.sceneform.math.Vector3(worldPos.x, worldPos.y, worldPos.z)); | ||
this.android.setLookDirection(direction, com.google.ar.sceneform.math.Vector3.up()); | ||
}; | ||
ARCommonNode.prototype.lookAtPosition = function (localPos) { | ||
var direction = com.google.ar.sceneform.math.Vector3.subtract(this.android.getWorldPosition(), this.android.localToWorldPoint(new com.google.ar.sceneform.math.Vector3(localPos.x, localPos.y, localPos.z))); | ||
} | ||
lookAtPosition(localPos) { | ||
const direction = com.google.ar.sceneform.math.Vector3.subtract(this.android.getWorldPosition(), this.android.localToWorldPoint(new com.google.ar.sceneform.math.Vector3(localPos.x, localPos.y, localPos.z))); | ||
this.android.setLookDirection(direction, com.google.ar.sceneform.math.Vector3.up()); | ||
}; | ||
ARCommonNode.prototype.lookAtNode = function (node) { | ||
} | ||
lookAtNode(node) { | ||
this.lookAtWorldPosition(node.getWorldPosition()); | ||
}; | ||
ARCommonNode.prototype.getPositionOnScreen = function () { | ||
var screenPoint = ARCommonNode.camera.worldToScreenPoint(this.android.getWorldPosition()); | ||
} | ||
getPositionOnScreen() { | ||
const screenPoint = ARCommonNode.camera.worldToScreenPoint(this.android.getWorldPosition()); | ||
return { | ||
@@ -135,45 +134,45 @@ x: screenPoint.x / ARCommonNode.screenScale, | ||
}; | ||
}; | ||
ARCommonNode.prototype.scaleBy = function (by) { | ||
var currentScale = this.android.getLocalScale(); | ||
} | ||
scaleBy(by) { | ||
const currentScale = this.android.getLocalScale(); | ||
this.android.setLocalScale(new com.google.ar.sceneform.math.Vector3(currentScale.x + (by instanceof ar_common_1.ARScale ? by.x : by), currentScale.y + (by instanceof ar_common_1.ARScale ? by.y : by), currentScale.z + (by instanceof ar_common_1.ARScale ? by.z : by))); | ||
}; | ||
ARCommonNode.prototype.scaleTo = function (scale) { | ||
} | ||
scaleTo(scale) { | ||
this.android.setLocalScale(new com.google.ar.sceneform.math.Vector3((scale instanceof ar_common_1.ARScale ? scale.x : scale), (scale instanceof ar_common_1.ARScale ? scale.y : scale), (scale instanceof ar_common_1.ARScale ? scale.z : scale))); | ||
}; | ||
ARCommonNode.prototype.onTap = function (touchPosition) { | ||
} | ||
onTap(touchPosition) { | ||
this.onTapHandler && this.onTapHandler({ | ||
node: this, | ||
touchPosition: touchPosition | ||
touchPosition | ||
}); | ||
}; | ||
ARCommonNode.prototype.onLongPress = function (touchPosition) { | ||
} | ||
onLongPress(touchPosition) { | ||
this.onLongPressHandler && this.onLongPressHandler({ | ||
node: this, | ||
touchPosition: touchPosition | ||
touchPosition | ||
}); | ||
}; | ||
ARCommonNode.prototype.onPan = function (touchPosition) { | ||
} | ||
onPan(touchPosition) { | ||
this.onPanHandler && this.onPanHandler({ | ||
node: this, | ||
touchPosition: touchPosition | ||
touchPosition | ||
}); | ||
}; | ||
ARCommonNode.prototype.setVisible = function (visible) { | ||
} | ||
setVisible(visible) { | ||
this.android.setEnabled(visible); | ||
}; | ||
ARCommonNode.prototype.allowDragging = function () { | ||
} | ||
allowDragging() { | ||
return this.draggingEnabled; | ||
}; | ||
ARCommonNode.prototype.allowRotating = function () { | ||
} | ||
allowRotating() { | ||
return this.rotatingEnabled; | ||
}; | ||
ARCommonNode.prototype.allowScaling = function () { | ||
} | ||
allowScaling() { | ||
return this.scalingEnabled; | ||
}; | ||
ARCommonNode.prototype.remove = function () { | ||
} | ||
remove() { | ||
this.android.setParent(null); | ||
}; | ||
ARCommonNode.getDefaultMaterial = function () { | ||
return new Promise(function (resolve, reject) { | ||
} | ||
static getDefaultMaterial() { | ||
return new Promise((resolve, reject) => { | ||
if (ARCommonNode.defaultMaterial) { | ||
@@ -185,3 +184,3 @@ resolve(ARCommonNode.defaultMaterial); | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (material) { | ||
accept: material => { | ||
ARCommonNode.defaultMaterial = material; | ||
@@ -192,12 +191,11 @@ resolve(material); | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { return reject(error); } | ||
apply: error => reject(error) | ||
})); | ||
}); | ||
}; | ||
ARCommonNode.degToRadians = function (degrees) { | ||
} | ||
static degToRadians(degrees) { | ||
return degrees * (3.14159265359 / 180); | ||
}; | ||
ARCommonNode.screenScale = core_1.Screen.mainScreen.scale; | ||
return ARCommonNode; | ||
}()); | ||
} | ||
} | ||
exports.ARCommonNode = ARCommonNode; | ||
ARCommonNode.screenScale = core_1.Screen.mainScreen.scale; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARCommonGeometryNode = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var armaterialfactory_1 = require("./armaterialfactory"); | ||
var ARCommonGeometryNode = (function (_super) { | ||
__extends(ARCommonGeometryNode, _super); | ||
function ARCommonGeometryNode(options, node) { | ||
var _this = _super.call(this, options, node) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
const armaterialfactory_1 = require("./armaterialfactory"); | ||
class ARCommonGeometryNode extends arcommon_1.ARCommonNode { | ||
constructor(options, node) { | ||
super(options, node); | ||
if (options.materials) { | ||
var material = options.materials[0]; | ||
let material = options.materials[0]; | ||
armaterialfactory_1.ARMaterialFactory.applyMaterial(node, material); | ||
} | ||
return _this; | ||
} | ||
ARCommonGeometryNode.prototype.setMaterials = function (materials) { | ||
armaterialfactory_1.ARMaterialFactory.applyMaterial(this.android, materials[0]).catch(function (e) { return console.log(e); }); | ||
}; | ||
return ARCommonGeometryNode; | ||
}(arcommon_1.ARCommonNode)); | ||
setMaterials(materials) { | ||
armaterialfactory_1.ARMaterialFactory.applyMaterial(this.android, materials[0]).catch((e) => console.log(e)); | ||
} | ||
} | ||
exports.ARCommonGeometryNode = ARCommonGeometryNode; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARGroup = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var ARGroup = (function (_super) { | ||
__extends(ARGroup, _super); | ||
function ARGroup() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
class ARGroup extends arcommon_1.ARCommonNode { | ||
static create(options, fragment) { | ||
return new Promise(async (resolve, reject) => { | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
resolve(new ARGroup(options, node)); | ||
}); | ||
} | ||
ARGroup.create = function (options, fragment) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var node; | ||
return __generator(this, function (_a) { | ||
node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
resolve(new ARGroup(options, node)); | ||
return [2]; | ||
}); | ||
}); }); | ||
}; | ||
return ARGroup; | ||
}(arcommon_1.ARCommonNode)); | ||
} | ||
exports.ARGroup = ARGroup; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARImage = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var pixelsPerMeter = 500; | ||
var ARImage = (function (_super) { | ||
__extends(ARImage, _super); | ||
function ARImage() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARImage.create = function (options, fragment) { | ||
var _this = this; | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
const pixelsPerMeter = 500; | ||
class ARImage extends arcommon_1.ARCommonNode { | ||
static create(options, fragment) { | ||
if (typeof options.image === "string") { | ||
if (options.image.indexOf("://") >= 0) { | ||
return core_1.ImageSource.fromUrl(options.image).then(function (image) { | ||
return core_1.ImageSource.fromUrl(options.image).then(image => { | ||
options.image = image; | ||
@@ -23,35 +18,30 @@ return ARImage.create(options, fragment); | ||
} | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var image, context, imageView; | ||
return __generator(this, function (_a) { | ||
image = options.image.android; | ||
context = core_1.Utils.ad.getApplicationContext(); | ||
imageView = new android.widget.ImageView(context); | ||
imageView.setImageBitmap(image); | ||
com.google.ar.sceneform.rendering.ViewRenderable.builder() | ||
.setView(context, imageView) | ||
.build() | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (renderable) { | ||
if (options.dimensions) { | ||
renderable.setSizer(new com.google.ar.sceneform.rendering.FixedWidthViewSizer(options.dimensions.x)); | ||
} | ||
else { | ||
renderable.setSizer(new com.google.ar.sceneform.rendering.DpToMetersViewSizer(pixelsPerMeter)); | ||
} | ||
renderable.setVerticalAlignment(com.google.ar.sceneform.rendering.ViewRenderable.VerticalAlignment.CENTER); | ||
var node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
node.setRenderable(renderable); | ||
resolve(new ARImage(options, node)); | ||
return new Promise(async (resolve, reject) => { | ||
const image = options.image.android; | ||
const context = core_1.Utils.ad.getApplicationContext(); | ||
const imageView = new android.widget.ImageView(context); | ||
imageView.setImageBitmap(image); | ||
com.google.ar.sceneform.rendering.ViewRenderable.builder() | ||
.setView(context, imageView) | ||
.build() | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: renderable => { | ||
if (options.dimensions) { | ||
renderable.setSizer(new com.google.ar.sceneform.rendering.FixedWidthViewSizer(options.dimensions.x)); | ||
} | ||
})) | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { return reject(error); } | ||
})); | ||
return [2]; | ||
}); | ||
}); }); | ||
}; | ||
return ARImage; | ||
}(arcommon_1.ARCommonNode)); | ||
else { | ||
renderable.setSizer(new com.google.ar.sceneform.rendering.DpToMetersViewSizer(pixelsPerMeter)); | ||
} | ||
renderable.setVerticalAlignment(com.google.ar.sceneform.rendering.ViewRenderable.VerticalAlignment.CENTER); | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
node.setRenderable(renderable); | ||
resolve(new ARImage(options, node)); | ||
} | ||
})) | ||
.exceptionally(new java.util.function.Function({ | ||
apply: error => reject(error) | ||
})); | ||
}); | ||
} | ||
} | ||
exports.ARImage = ARImage; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARMaterialFactory = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var ARMaterialFactory = (function () { | ||
function ARMaterialFactory() { | ||
} | ||
ARMaterialFactory.applyMaterial = function (node, material) { | ||
const core_1 = require("@nativescript/core"); | ||
class ARMaterialFactory { | ||
static applyMaterial(node, material) { | ||
if (typeof material === "string") { | ||
return new Promise(function (resolve, reject) { | ||
return new Promise((resolve, reject) => { | ||
reject("not implemented"); | ||
@@ -16,15 +14,15 @@ }); | ||
return ARMaterialFactory.applyColor(node, material.android) | ||
.catch(function (err) { return console.log("Error applying material: " + err); }); | ||
.catch(err => console.log("Error applying material: " + err)); | ||
} | ||
else { | ||
return ARMaterialFactory.applyARMaterial(node, material) | ||
.catch(function (err) { return console.log("Error applying material: " + err); }); | ||
.catch(err => console.log("Error applying material: " + err)); | ||
} | ||
}; | ||
ARMaterialFactory.applyColor = function (node, color) { | ||
return new Promise(function (resolve, reject) { | ||
} | ||
static applyColor(node, color) { | ||
return new Promise((resolve, reject) => { | ||
com.google.ar.sceneform.rendering.MaterialFactory.makeOpaqueWithColor(core_1.Utils.ad.getApplicationContext(), new com.google.ar.sceneform.rendering.Color(color)) | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (material) { | ||
var renderable = node.getRenderable(); | ||
accept: material => { | ||
const renderable = node.getRenderable(); | ||
if (renderable) { | ||
@@ -37,12 +35,12 @@ renderable.setMaterial(material); | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { return reject(error); } | ||
apply: error => reject(error) | ||
})); | ||
}); | ||
}; | ||
ARMaterialFactory.applyARMaterial = function (node, material) { | ||
return new Promise(function (resolve, reject) { | ||
} | ||
static applyARMaterial(node, material) { | ||
return new Promise((resolve, reject) => { | ||
android.os.AsyncTask.execute(new java.lang.Runnable({ | ||
run: function () { | ||
var gltf = blankGLTF(); | ||
var index = 0; | ||
run: () => { | ||
let gltf = blankGLTF(); | ||
let index = 0; | ||
if (material.diffuse) { | ||
@@ -111,17 +109,17 @@ if (material.diffuse.constructor.name === "Color") { | ||
} | ||
var p = core_1.path.join(core_1.knownFolders.temp().path, "ar-" + (new Date()).getTime()); | ||
var tmp = core_1.Folder.fromPath(p); | ||
var file = tmp.getFile("model_source.gltf"); | ||
var modelPath = file.path; | ||
var promise = file.writeText(JSON.stringify(gltf, null, " ")) | ||
.then(function () { return copyAsset("material.bin", tmp.getFile("material.bin").path); }); | ||
gltf.images.forEach(function (image) { | ||
promise = promise.then(function () { | ||
const p = core_1.path.join(core_1.knownFolders.temp().path, "ar-" + (new Date()).getTime()); | ||
const tmp = core_1.Folder.fromPath(p); | ||
const file = tmp.getFile("model_source.gltf"); | ||
const modelPath = file.path; | ||
let promise = file.writeText(JSON.stringify(gltf, null, " ")) | ||
.then(() => copyAsset("material.bin", tmp.getFile("material.bin").path)); | ||
gltf.images.forEach(image => { | ||
promise = promise.then(() => { | ||
return copyAsset(image.uri, tmp.getFile(image.uri).path) | ||
.catch(function (err) { return console.log("Failed to copy " + image.uri + " with error: " + err); }); | ||
.catch(err => console.log("Failed to copy " + image.uri + " with error: " + err)); | ||
}); | ||
}); | ||
promise.then(function () { | ||
var context = core_1.Utils.ad.getApplicationContext(); | ||
var model = com.google.ar.sceneform.assets.RenderableSource.builder().setSource(context, android.net.Uri.parse(modelPath), com.google.ar.sceneform.assets.RenderableSource.SourceType.GLTF2).build(); | ||
promise.then(() => { | ||
let context = core_1.Utils.ad.getApplicationContext(); | ||
let model = com.google.ar.sceneform.assets.RenderableSource.builder().setSource(context, android.net.Uri.parse(modelPath), com.google.ar.sceneform.assets.RenderableSource.SourceType.GLTF2).build(); | ||
com.google.ar.sceneform.rendering.ModelRenderable.builder() | ||
@@ -131,3 +129,3 @@ .setSource(context, model) | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (renderable) { | ||
accept: renderable => { | ||
node.getRenderable().setMaterial(renderable.getMaterial()); | ||
@@ -137,3 +135,3 @@ } | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { | ||
apply: error => { | ||
console.error("failed loading custom material: " + error); | ||
@@ -143,3 +141,3 @@ reject(error); | ||
})); | ||
}).catch(function (err) { | ||
}).catch((err) => { | ||
console.error("failed to load custom material"); | ||
@@ -152,7 +150,6 @@ console.log(err); | ||
}); | ||
}; | ||
return ARMaterialFactory; | ||
}()); | ||
} | ||
} | ||
exports.ARMaterialFactory = ARMaterialFactory; | ||
var getWrapMode = function (wrapMode) { | ||
const getWrapMode = (wrapMode) => { | ||
if (wrapMode === "Mirror") { | ||
@@ -171,10 +168,10 @@ return 33648; | ||
}; | ||
var counter = 0; | ||
var copyAsset = function (asset, to) { | ||
return new Promise(function (resolve, reject) { | ||
var context = core_1.Utils.ad.getApplicationContext(); | ||
var input = context.getAssets().open(asset); | ||
var out = new java.io.FileOutputStream(new java.io.File(to)); | ||
var buf = Array.create("byte", 1024); | ||
var len; | ||
let counter = 0; | ||
const copyAsset = (asset, to) => { | ||
return new Promise((resolve, reject) => { | ||
const context = core_1.Utils.ad.getApplicationContext(); | ||
let input = context.getAssets().open(asset); | ||
let out = new java.io.FileOutputStream(new java.io.File(to)); | ||
let buf = Array.create("byte", 1024); | ||
let len; | ||
while ((len = input.read(buf)) > 0) { | ||
@@ -188,14 +185,14 @@ out.write(buf, 0, len); | ||
}; | ||
var colorFrom = function (color) { | ||
var c = new com.google.ar.sceneform.rendering.Color(color.android); | ||
const colorFrom = (color) => { | ||
const c = new com.google.ar.sceneform.rendering.Color(color.android); | ||
return [c.r, c.g, c.b, c.a]; | ||
}; | ||
var addPbrMetallic = function (gltf, property) { | ||
const addPbrMetallic = (gltf, property) => { | ||
if (gltf.materials[0]["pbrMetallicRoughness"] === undefined) { | ||
gltf.materials[0]["pbrMetallicRoughness"] = {}; | ||
} | ||
Object.keys(property).forEach(function (key) { return gltf.materials[0]["pbrMetallicRoughness"][key] = property[key]; }); | ||
Object.keys(property).forEach(key => gltf.materials[0]["pbrMetallicRoughness"][key] = property[key]); | ||
}; | ||
var addTexture = function (gltf, material, index) { | ||
var property = (typeof material === "string" ? { | ||
const addTexture = (gltf, material, index) => { | ||
let property = (typeof material === "string" ? { | ||
contents: material, | ||
@@ -218,3 +215,3 @@ wrapMode: "Repeat" | ||
}; | ||
var blankGLTF = function () { | ||
const blankGLTF = () => { | ||
return { | ||
@@ -221,0 +218,0 @@ "asset": { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARModel = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARModel = (function (_super) { | ||
__extends(ARModel, _super); | ||
function ARModel() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARModel.create = function (options, fragment) { | ||
return new Promise(function (resolve, reject) { | ||
var model; | ||
var context = core_1.Utils.ad.getApplicationContext(); | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARModel extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, fragment) { | ||
return new Promise((resolve, reject) => { | ||
let model; | ||
const context = core_1.Utils.ad.getApplicationContext(); | ||
if (options.name.indexOf(".glb") > 0 || options.name.indexOf(".gltf") > 0) { | ||
@@ -26,4 +22,4 @@ model = ARModel.getGLTFSource(options.name); | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (renderable) { | ||
var transformableNode = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
accept: renderable => { | ||
const transformableNode = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
transformableNode.setRenderable(renderable); | ||
@@ -34,3 +30,3 @@ resolve(new ARModel(options, transformableNode)); | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { | ||
apply: error => { | ||
console.error("failed loading '" + options.name + "': " + error); | ||
@@ -41,12 +37,11 @@ reject(error); | ||
}); | ||
}; | ||
ARModel.getGLTFSource = function (asset) { | ||
var context = core_1.Utils.ad.getApplicationContext(); | ||
var type = (asset.indexOf(".glb") > 0) | ||
} | ||
static getGLTFSource(asset) { | ||
const context = core_1.Utils.ad.getApplicationContext(); | ||
const type = (asset.indexOf(".glb") > 0) | ||
? com.google.ar.sceneform.assets.RenderableSource.SourceType.GLB | ||
: com.google.ar.sceneform.assets.RenderableSource.SourceType.GLTF2; | ||
return com.google.ar.sceneform.assets.RenderableSource.builder().setSource(context, android.net.Uri.parse(asset), type).build(); | ||
}; | ||
return ARModel; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
} | ||
exports.ARModel = ARModel; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARPlane = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARPlane = (function (_super) { | ||
__extends(ARPlane, _super); | ||
function ARPlane() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARPlane extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, fragment) { | ||
return new Promise(async (resolve, reject) => { | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
const defaultMaterial = await arcommon_1.ARCommonNode.getDefaultMaterial(); | ||
const size = new com.google.ar.sceneform.math.Vector3(options.dimensions instanceof Object ? options.dimensions.x : options.dimensions, options.dimensions instanceof Object ? options.dimensions.y : options.dimensions, 0.01); | ||
const center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
const renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeCube(size, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARPlane(options, node)); | ||
}); | ||
} | ||
ARPlane.create = function (options, fragment) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var node, defaultMaterial, size, center, renderable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
return [4, arcommon_1.ARCommonNode.getDefaultMaterial()]; | ||
case 1: | ||
defaultMaterial = _a.sent(); | ||
size = new com.google.ar.sceneform.math.Vector3(options.dimensions instanceof Object ? options.dimensions.x : options.dimensions, options.dimensions instanceof Object ? options.dimensions.y : options.dimensions, 0.01); | ||
center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeCube(size, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARPlane(options, node)); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
return ARPlane; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
exports.ARPlane = ARPlane; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARSphere = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARSphere = (function (_super) { | ||
__extends(ARSphere, _super); | ||
function ARSphere() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARSphere extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, fragment) { | ||
return new Promise(async (resolve, reject) => { | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
const defaultMaterial = await arcommon_1.ARCommonNode.getDefaultMaterial(); | ||
const radius = options.radius; | ||
const center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
const renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeSphere(radius, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARSphere(options, node)); | ||
}); | ||
} | ||
ARSphere.create = function (options, fragment) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var node, defaultMaterial, radius, center, renderable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
return [4, arcommon_1.ARCommonNode.getDefaultMaterial()]; | ||
case 1: | ||
defaultMaterial = _a.sent(); | ||
radius = options.radius; | ||
center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeSphere(radius, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARSphere(options, node)); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
return ARSphere; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
exports.ARSphere = ARSphere; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARTube = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARTube = (function (_super) { | ||
__extends(ARTube, _super); | ||
function ARTube() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARTube extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, fragment) { | ||
return new Promise(async (resolve, reject) => { | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
const defaultMaterial = await arcommon_1.ARCommonNode.getDefaultMaterial(); | ||
const radius = options.outerRadius; | ||
const height = options.height; | ||
const center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
const renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeCylinder(radius, height, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARTube(options, node)); | ||
}); | ||
} | ||
ARTube.create = function (options, fragment) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var node, defaultMaterial, radius, height, center, renderable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
return [4, arcommon_1.ARCommonNode.getDefaultMaterial()]; | ||
case 1: | ||
defaultMaterial = _a.sent(); | ||
radius = options.outerRadius; | ||
height = options.height; | ||
center = new com.google.ar.sceneform.math.Vector3(0, 0, 0); | ||
renderable = com.google.ar.sceneform.rendering.ShapeFactory.makeCylinder(radius, height, center, defaultMaterial); | ||
node.setRenderable(renderable); | ||
resolve(new ARTube(options, node)); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
return ARTube; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
exports.ARTube = ARTube; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARUIView = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var ARUIView = (function (_super) { | ||
__extends(ARUIView, _super); | ||
function ARUIView() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARUIView.create = function (options, fragment) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var node, context, container, view, label, customUI; | ||
return __generator(this, function (_a) { | ||
node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
context = core_1.Utils.ad.getApplicationContext(); | ||
container = new android.widget.LinearLayout(context); | ||
container.setOrientation(android.widget.LinearLayout.VERTICAL); | ||
view = options.view; | ||
if (!view) { | ||
label = new android.widget.TextView(context); | ||
label.setText("Hello World"); | ||
label.setShadowLayer(4, 0, 0, android.graphics.Color.WHITE); | ||
label.setTextColor(android.graphics.Color.BLACK); | ||
container.addView(label); | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
class ARUIView extends arcommon_1.ARCommonNode { | ||
static create(options, fragment) { | ||
return new Promise(async (resolve, reject) => { | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
const context = core_1.Utils.ad.getApplicationContext(); | ||
const container = new android.widget.LinearLayout(context); | ||
container.setOrientation(android.widget.LinearLayout.VERTICAL); | ||
const view = options.view; | ||
if (!view) { | ||
const label = new android.widget.TextView(context); | ||
label.setText("Hello World"); | ||
label.setShadowLayer(4, 0, 0, android.graphics.Color.WHITE); | ||
label.setTextColor(android.graphics.Color.BLACK); | ||
container.addView(label); | ||
} | ||
else { | ||
if (view.android && view.android.getParent()) { | ||
view.android.getParent().removeView(view.android); | ||
} | ||
else { | ||
if (view.android && view.android.getParent()) { | ||
view.android.getParent().removeView(view.android); | ||
} | ||
if (!view.android) { | ||
view._setupUI(context); | ||
view.loadView(view); | ||
view.requestLayout(); | ||
} | ||
container.addView(view.android); | ||
if (!view.android) { | ||
view._setupUI(context); | ||
view.loadView(view); | ||
view.requestLayout(); | ||
} | ||
customUI = com.google.ar.sceneform.rendering.ViewRenderable.builder() | ||
.setView(context, container) | ||
.build() | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (renderable) { | ||
console.log(">> accepted2, renderable: " + renderable); | ||
renderable.setVerticalAlignment(com.google.ar.sceneform.rendering.ViewRenderable.VerticalAlignment.BOTTOM); | ||
node.setRenderable(renderable); | ||
resolve(new ARUIView(options, node)); | ||
} | ||
})) | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { return reject(error); } | ||
})); | ||
return [2]; | ||
}); | ||
}); }); | ||
}; | ||
return ARUIView; | ||
}(arcommon_1.ARCommonNode)); | ||
container.addView(view.android); | ||
} | ||
const customUI = com.google.ar.sceneform.rendering.ViewRenderable.builder() | ||
.setView(context, container) | ||
.build() | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: renderable => { | ||
console.log(">> accepted2, renderable: " + renderable); | ||
renderable.setVerticalAlignment(com.google.ar.sceneform.rendering.ViewRenderable.VerticalAlignment.BOTTOM); | ||
node.setRenderable(renderable); | ||
resolve(new ARUIView(options, node)); | ||
} | ||
})) | ||
.exceptionally(new java.util.function.Function({ | ||
apply: error => reject(error) | ||
})); | ||
}); | ||
} | ||
} | ||
exports.ARUIView = ARUIView; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARVideo = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var pixelsPerMeter = 500; | ||
var alignCenter = function (node) { | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
let pixelsPerMeter = 500; | ||
const alignCenter = (node) => { | ||
node.setLocalPosition(new com.google.ar.sceneform.math.Vector3(0, -node.getLocalScale().y / 2, 0)); | ||
}; | ||
var alignBottom = function (node) { | ||
const alignBottom = (node) => { | ||
node.setLocalPosition(new com.google.ar.sceneform.math.Vector3(0, 0, 0)); | ||
}; | ||
var ARVideo = (function (_super) { | ||
__extends(ARVideo, _super); | ||
function ARVideo() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
class ARVideo extends arcommon_1.ARCommonNode { | ||
isPlaying() { | ||
return this.mediaPlayer && this.mediaPlayer.isPlaying(); | ||
} | ||
ARVideo.prototype.isPlaying = function () { | ||
return this.mediaPlayer && this.mediaPlayer.isPlaying(); | ||
}; | ||
ARVideo.prototype.play = function () { | ||
play() { | ||
if (this.mediaPlayer) { | ||
this.mediaPlayer.start(); | ||
} | ||
}; | ||
ARVideo.prototype.pause = function () { | ||
} | ||
pause() { | ||
if (this.mediaPlayer) { | ||
this.mediaPlayer.pause(); | ||
} | ||
}; | ||
ARVideo.create = function (options, fragment) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var node, videoNode, size, texture, mediaPlayer, loop, videoMat; | ||
return __generator(this, function (_a) { | ||
node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
videoNode = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
videoNode.setParent(node); | ||
size = new com.google.ar.sceneform.math.Vector3(options.dimensions instanceof Object ? options.dimensions.x : options.dimensions || 0.96, options.dimensions instanceof Object ? options.dimensions.y : options.dimensions || 0.56, 1); | ||
videoNode.setLocalScale(size); | ||
alignCenter(videoNode); | ||
texture = new com.google.ar.sceneform.rendering.ExternalTexture(); | ||
mediaPlayer = ARVideo.getPlayer(options); | ||
mediaPlayer.setSurface(texture.getSurface()); | ||
mediaPlayer.setVideoScalingMode(android.media.MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING); | ||
loop = options.loop !== false; | ||
if (loop) { | ||
mediaPlayer.setLooping(true); | ||
} | ||
ARVideo.getModel().then(function (renderable) { | ||
videoMat = renderable.getMaterial(); | ||
com.google.ar.sceneform.rendering.MaterialFactory.makeOpaqueWithColor(core_1.Utils.ad.getApplicationContext(), new com.google.ar.sceneform.rendering.Color(android.graphics.Color.MAGENTA)) | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (material) { | ||
renderable.setMaterial(material); | ||
videoNode.setRenderable(renderable); | ||
var arVideo = new ARVideo(options, node); | ||
arVideo.mediaPlayer = mediaPlayer; | ||
resolve(arVideo); | ||
} | ||
static create(options, fragment) { | ||
return new Promise(async (resolve, reject) => { | ||
const node = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
const videoNode = arcommon_1.ARCommonNode.createNode(options, fragment); | ||
videoNode.setParent(node); | ||
const size = new com.google.ar.sceneform.math.Vector3(options.dimensions instanceof Object ? options.dimensions.x : options.dimensions || 0.96, options.dimensions instanceof Object ? options.dimensions.y : options.dimensions || 0.56, 1); | ||
videoNode.setLocalScale(size); | ||
alignCenter(videoNode); | ||
const texture = new com.google.ar.sceneform.rendering.ExternalTexture(); | ||
const mediaPlayer = ARVideo.getPlayer(options); | ||
mediaPlayer.setSurface(texture.getSurface()); | ||
mediaPlayer.setVideoScalingMode(android.media.MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING); | ||
const loop = options.loop !== false; | ||
if (loop) { | ||
mediaPlayer.setLooping(true); | ||
} | ||
let videoMat; | ||
ARVideo.getModel().then(renderable => { | ||
videoMat = renderable.getMaterial(); | ||
com.google.ar.sceneform.rendering.MaterialFactory.makeOpaqueWithColor(core_1.Utils.ad.getApplicationContext(), new com.google.ar.sceneform.rendering.Color(android.graphics.Color.MAGENTA)) | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: material => { | ||
renderable.setMaterial(material); | ||
videoNode.setRenderable(renderable); | ||
const arVideo = new ARVideo(options, node); | ||
arVideo.mediaPlayer = mediaPlayer; | ||
resolve(arVideo); | ||
} | ||
})) | ||
.exceptionally(new java.util.function.Function({ | ||
apply: error => reject(error) | ||
})); | ||
videoMat.setExternalTexture("videoTexture", texture); | ||
videoMat.setBoolean("disableChromaKey", true); | ||
mediaPlayer.setOnPreparedListener(new android.media.MediaPlayer.OnPreparedListener({ | ||
onPrepared: (mp) => { | ||
const width = mp.getVideoWidth(); | ||
const height = mp.getVideoHeight(); | ||
if (!options.dimensions) { | ||
videoNode.setLocalScale(new com.google.ar.sceneform.math.Vector3(width / pixelsPerMeter, height / pixelsPerMeter, 1)); | ||
} | ||
})) | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { return reject(error); } | ||
})); | ||
videoMat.setExternalTexture("videoTexture", texture); | ||
videoMat.setBoolean("disableChromaKey", true); | ||
mediaPlayer.setOnPreparedListener(new android.media.MediaPlayer.OnPreparedListener({ | ||
onPrepared: function (mp) { | ||
var width = mp.getVideoWidth(); | ||
var height = mp.getVideoHeight(); | ||
if (!options.dimensions) { | ||
videoNode.setLocalScale(new com.google.ar.sceneform.math.Vector3(width / pixelsPerMeter, height / pixelsPerMeter, 1)); | ||
alignCenter(videoNode); | ||
console.log([height, width]); | ||
mediaPlayer.start(); | ||
texture | ||
.getSurfaceTexture() | ||
.setOnFrameAvailableListener(new android.graphics.SurfaceTexture.OnFrameAvailableListener({ | ||
onFrameAvailable: (surfaceTexture) => { | ||
console.log('available'); | ||
try { | ||
renderable.setMaterial(videoMat); | ||
texture.getSurfaceTexture().setOnFrameAvailableListener(null); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
alignCenter(videoNode); | ||
console.log([height, width]); | ||
mediaPlayer.start(); | ||
texture | ||
.getSurfaceTexture() | ||
.setOnFrameAvailableListener(new android.graphics.SurfaceTexture.OnFrameAvailableListener({ | ||
onFrameAvailable: function (surfaceTexture) { | ||
console.log('available'); | ||
try { | ||
renderable.setMaterial(videoMat); | ||
texture.getSurfaceTexture().setOnFrameAvailableListener(null); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
})); | ||
} | ||
})); | ||
mediaPlayer.prepareAsync(); | ||
}).catch(console.error); | ||
return [2]; | ||
}); | ||
}); }); | ||
}; | ||
ARVideo.getModel = function () { | ||
return new Promise(function (resolve, reject) { | ||
})); | ||
} | ||
})); | ||
mediaPlayer.prepareAsync(); | ||
}).catch(console.error); | ||
}); | ||
} | ||
static getModel() { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
@@ -106,3 +98,3 @@ com.google.ar.sceneform.rendering.ModelRenderable.builder() | ||
.thenAccept(new java.util.function.Consumer({ | ||
accept: function (renderable) { | ||
accept: renderable => { | ||
resolve(renderable); | ||
@@ -112,3 +104,3 @@ } | ||
.exceptionally(new java.util.function.Function({ | ||
apply: function (error) { | ||
apply: error => { | ||
console.log("g"); | ||
@@ -123,9 +115,9 @@ reject(error); | ||
}); | ||
}; | ||
ARVideo.getPlayer = function (options) { | ||
var video = options.video; | ||
var context = core_1.Utils.ad.getApplicationContext(); | ||
} | ||
static getPlayer(options) { | ||
const video = options.video; | ||
const context = core_1.Utils.ad.getApplicationContext(); | ||
if (typeof video === "string") { | ||
try { | ||
var mediaPlayer = new android.media.MediaPlayer(); | ||
const mediaPlayer = new android.media.MediaPlayer(); | ||
if (video.indexOf("://") >= 0) { | ||
@@ -138,3 +130,3 @@ mediaPlayer.setDataSource(context, android.net.Uri.parse(video)); | ||
mediaPlayer.setOnErrorListener(new android.media.MediaPlayer.OnErrorListener({ | ||
onError: function (mp, what, extra) { | ||
onError: (mp, what, extra) => { | ||
console.error("MediaPlayer Error " + what + " with " + video); | ||
@@ -149,3 +141,3 @@ ([ | ||
[android.media.MediaPlayer.MEDIA_ERROR_UNSUPPORTED, "MEDIA_ERROR_UNSUPPORTED"] | ||
]).forEach(function (code) { | ||
]).forEach(code => { | ||
if (what === code[0]) { | ||
@@ -170,5 +162,4 @@ console.log(code[1]); | ||
throw 'Error'; | ||
}; | ||
return ARVideo; | ||
}(arcommon_1.ARCommonNode)); | ||
} | ||
} | ||
exports.ARVideo = ARVideo; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARBox = void 0; | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARBox = (function (_super) { | ||
__extends(ARBox, _super); | ||
function ARBox() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARBox.create = function (options, renderer) { | ||
var dimensions = (typeof options.dimensions !== "number" ? options.dimensions : { | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARBox extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, renderer) { | ||
const dimensions = (typeof options.dimensions !== "number" ? options.dimensions : { | ||
x: options.dimensions, | ||
@@ -16,7 +12,6 @@ y: options.dimensions, | ||
}); | ||
var box = SCNBox.boxWithWidthHeightLengthChamferRadius(dimensions.x, dimensions.y, dimensions.z, options.chamferRadius || 0.0); | ||
const box = SCNBox.boxWithWidthHeightLengthChamferRadius(dimensions.x, dimensions.y, dimensions.z, options.chamferRadius || 0.0); | ||
return new ARBox(options, SCNNode.nodeWithGeometry(box), renderer); | ||
}; | ||
return ARBox; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
} | ||
exports.ARBox = ARBox; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARCommonNode = void 0; | ||
var ar_common_1 = require("../../ar-common"); | ||
var ARCommonNode = (function () { | ||
function ARCommonNode(options, node, renderer) { | ||
const ar_common_1 = require("../../ar-common"); | ||
class ARCommonNode { | ||
constructor(options, node, renderer) { | ||
this.renderer = renderer; | ||
@@ -24,6 +24,6 @@ this.draggingEnabled = options.draggingEnabled; | ||
if (!this.onTapHandler) { | ||
this.onTapHandler = (function (interaction) { return options.parentNode.onTap(interaction.touchPosition); }); | ||
this.onTapHandler = (interaction => options.parentNode.onTap(interaction.touchPosition)); | ||
} | ||
if (!this.onLongPressHandler) { | ||
this.onLongPressHandler = (function (interaction) { return options.parentNode.onLongPress(interaction.touchPosition); }); | ||
this.onLongPressHandler = (interaction => options.parentNode.onLongPress(interaction.touchPosition)); | ||
} | ||
@@ -45,3 +45,3 @@ } | ||
} | ||
ARCommonNode.prototype.moveTo = function (to) { | ||
moveTo(to) { | ||
this.ios.position = { | ||
@@ -52,4 +52,4 @@ x: to.x !== undefined ? to.x : this.ios.position.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.moveBy = function (by) { | ||
} | ||
moveBy(by) { | ||
this.ios.position = { | ||
@@ -60,5 +60,5 @@ x: this.ios.position.x + by.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.getPosition = function () { | ||
var pos = this.ios.position; | ||
} | ||
getPosition() { | ||
const pos = this.ios.position; | ||
return { | ||
@@ -69,5 +69,5 @@ x: pos.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.getWorldPosition = function () { | ||
var pos = this.ios.worldPosition; | ||
} | ||
getWorldPosition() { | ||
const pos = this.ios.worldPosition; | ||
return { | ||
@@ -78,5 +78,5 @@ x: pos.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.getDistanceTo = function (otherPosition) { | ||
var otherObjectWorldPos = this.renderer.unprojectPoint({ | ||
} | ||
getDistanceTo(otherPosition) { | ||
let otherObjectWorldPos = this.renderer.unprojectPoint({ | ||
x: otherPosition.x, | ||
@@ -86,9 +86,9 @@ y: otherPosition.y, | ||
}); | ||
var pos = this.ios.worldPosition; | ||
var xd = otherObjectWorldPos.x - pos.x; | ||
var yd = otherObjectWorldPos.y - pos.y; | ||
var zd = otherObjectWorldPos.z - pos.z; | ||
const pos = this.ios.worldPosition; | ||
let xd = otherObjectWorldPos.x - pos.x; | ||
let yd = otherObjectWorldPos.y - pos.y; | ||
let zd = otherObjectWorldPos.z - pos.z; | ||
return sqrt(xd * xd + yd * yd + zd * zd); | ||
}; | ||
ARCommonNode.prototype.setPosition = function (pos) { | ||
} | ||
setPosition(pos) { | ||
this.ios.position = { | ||
@@ -99,4 +99,4 @@ x: pos.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.setWorldPosition = function (pos) { | ||
} | ||
setWorldPosition(pos) { | ||
this.ios.worldPosition = { | ||
@@ -107,4 +107,4 @@ x: pos.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.rotateBy = function (by) { | ||
} | ||
rotateBy(by) { | ||
this.ios.eulerAngles = { | ||
@@ -115,4 +115,4 @@ x: this.ios.eulerAngles.x + ARCommonNode.degToRadians(by.x), | ||
}; | ||
}; | ||
ARCommonNode.prototype.setRotation = function (rot) { | ||
} | ||
setRotation(rot) { | ||
this.ios.eulerAngles = { | ||
@@ -123,18 +123,18 @@ x: ARCommonNode.degToRadians(rot.x), | ||
}; | ||
}; | ||
ARCommonNode.prototype.lookAtWorldPosition = function (worldPos) { | ||
} | ||
lookAtWorldPosition(worldPos) { | ||
this.ios.lookAt(worldPos); | ||
}; | ||
ARCommonNode.prototype.lookAtPosition = function (localPos) { | ||
var worldPos = this.ios.convertPositionToNode(localPos, null); | ||
} | ||
lookAtPosition(localPos) { | ||
const worldPos = this.ios.convertPositionToNode(localPos, null); | ||
this.lookAtWorldPosition(worldPos); | ||
}; | ||
ARCommonNode.prototype.lookAtNode = function (node) { | ||
} | ||
lookAtNode(node) { | ||
this.lookAtWorldPosition(node.getWorldPosition()); | ||
}; | ||
ARCommonNode.prototype.getPositionOnScreen = function () { | ||
} | ||
getPositionOnScreen() { | ||
if (!this.renderer) { | ||
return { x: 0, y: 0 }; | ||
} | ||
var positionOnScreen = this.renderer.projectPoint(this.ios.worldPosition); | ||
const positionOnScreen = this.renderer.projectPoint(this.ios.worldPosition); | ||
return { | ||
@@ -144,4 +144,4 @@ x: positionOnScreen.x, | ||
}; | ||
}; | ||
ARCommonNode.prototype.scaleBy = function (by) { | ||
} | ||
scaleBy(by) { | ||
this.ios.scale = { | ||
@@ -152,4 +152,4 @@ x: this.ios.scale.x + (by instanceof ar_common_1.ARScale ? by.x : by), | ||
}; | ||
}; | ||
ARCommonNode.prototype.scaleTo = function (scale) { | ||
} | ||
scaleTo(scale) { | ||
this.ios.scale = { | ||
@@ -160,41 +160,40 @@ x: (scale instanceof ar_common_1.ARScale ? scale.x : scale), | ||
}; | ||
}; | ||
ARCommonNode.prototype.onTap = function (touchPosition) { | ||
} | ||
onTap(touchPosition) { | ||
this.onTapHandler && this.onTapHandler({ | ||
node: this, | ||
touchPosition: touchPosition | ||
touchPosition | ||
}); | ||
}; | ||
ARCommonNode.prototype.onLongPress = function (touchPosition) { | ||
} | ||
onLongPress(touchPosition) { | ||
this.onLongPressHandler && this.onLongPressHandler({ | ||
node: this, | ||
touchPosition: touchPosition | ||
touchPosition | ||
}); | ||
}; | ||
ARCommonNode.prototype.onPan = function (touchPosition) { | ||
} | ||
onPan(touchPosition) { | ||
this.onPanHandler && this.onPanHandler({ | ||
node: this, | ||
touchPosition: touchPosition | ||
touchPosition | ||
}); | ||
}; | ||
ARCommonNode.prototype.setVisible = function (visible) { | ||
} | ||
setVisible(visible) { | ||
this.ios.hidden = !visible; | ||
}; | ||
ARCommonNode.prototype.allowDragging = function () { | ||
} | ||
allowDragging() { | ||
return this.draggingEnabled; | ||
}; | ||
ARCommonNode.prototype.allowRotating = function () { | ||
} | ||
allowRotating() { | ||
return this.rotatingEnabled; | ||
}; | ||
ARCommonNode.prototype.allowScaling = function () { | ||
} | ||
allowScaling() { | ||
return this.scalingEnabled; | ||
}; | ||
ARCommonNode.prototype.remove = function () { | ||
} | ||
remove() { | ||
this.ios.removeFromParentNode(); | ||
}; | ||
ARCommonNode.degToRadians = function (degrees) { | ||
} | ||
static degToRadians(degrees) { | ||
return degrees * (3.14159265359 / 180); | ||
}; | ||
return ARCommonNode; | ||
}()); | ||
} | ||
} | ||
exports.ARCommonNode = ARCommonNode; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARCommonGeometryNode = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var armaterialfactory_1 = require("./armaterialfactory"); | ||
var ARCommonGeometryNode = (function (_super) { | ||
__extends(ARCommonGeometryNode, _super); | ||
function ARCommonGeometryNode(options, node, renderer) { | ||
var _this = _super.call(this, options, node, renderer) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
const armaterialfactory_1 = require("./armaterialfactory"); | ||
class ARCommonGeometryNode extends arcommon_1.ARCommonNode { | ||
constructor(options, node, renderer) { | ||
super(options, node, renderer); | ||
if (options.materials) { | ||
ARCommonGeometryNode.applyMaterial(node, options.materials); | ||
} | ||
return _this; | ||
} | ||
ARCommonGeometryNode.applyMaterial = function (node, materials) { | ||
var materialArray = NSMutableArray.alloc().initWithCapacity(materials.length); | ||
materials.map(function (material) { return materialArray.addObject(armaterialfactory_1.ARMaterialFactory.getMaterial(material)); }); | ||
static applyMaterial(node, materials) { | ||
const materialArray = NSMutableArray.alloc().initWithCapacity(materials.length); | ||
materials.map(material => materialArray.addObject(armaterialfactory_1.ARMaterialFactory.getMaterial(material))); | ||
node.geometry.materials = materialArray; | ||
}; | ||
ARCommonGeometryNode.prototype.setMaterials = function (materials) { | ||
} | ||
setMaterials(materials) { | ||
ARCommonGeometryNode.applyMaterial(this.ios, materials); | ||
}; | ||
return ARCommonGeometryNode; | ||
}(arcommon_1.ARCommonNode)); | ||
} | ||
} | ||
exports.ARCommonGeometryNode = ARCommonGeometryNode; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARGroup = void 0; | ||
var arcommon_1 = require("./arcommon"); | ||
var ARGroup = (function (_super) { | ||
__extends(ARGroup, _super); | ||
function ARGroup() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommon_1 = require("./arcommon"); | ||
class ARGroup extends arcommon_1.ARCommonNode { | ||
static create(options, renderer) { | ||
return new ARGroup(options, SCNNode.node(), renderer); | ||
} | ||
ARGroup.create = function (options, renderer) { | ||
return new ARGroup(options, SCNNode.node(), renderer); | ||
}; | ||
return ARGroup; | ||
}(arcommon_1.ARCommonNode)); | ||
} | ||
exports.ARGroup = ARGroup; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARImage = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var pixelsPerMeter = 500; | ||
var ARImage = (function (_super) { | ||
__extends(ARImage, _super); | ||
function ARImage() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARImage.create = function (options, renderer) { | ||
var _this = this; | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
const pixelsPerMeter = 500; | ||
class ARImage extends arcommon_1.ARCommonNode { | ||
static create(options, renderer) { | ||
if (typeof options.image === "string") { | ||
@@ -23,23 +18,18 @@ if (options.image.indexOf("://") >= 0) { | ||
} | ||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () { | ||
var image, dimensions, materialPlane; | ||
return __generator(this, function (_a) { | ||
image = options.image.ios; | ||
if (!options.dimensions) { | ||
options.dimensions = { | ||
x: image.size.width / pixelsPerMeter, | ||
y: image.size.height / pixelsPerMeter | ||
}; | ||
} | ||
dimensions = options.dimensions; | ||
materialPlane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y); | ||
materialPlane.firstMaterial.diffuse.contents = image; | ||
materialPlane.firstMaterial.doubleSided = true; | ||
resolve(new ARImage(options, SCNNode.nodeWithGeometry(materialPlane), renderer)); | ||
return [2]; | ||
}); | ||
}); }); | ||
}; | ||
return ARImage; | ||
}(arcommon_1.ARCommonNode)); | ||
return new Promise(async (resolve, reject) => { | ||
const image = options.image.ios; | ||
if (!options.dimensions) { | ||
options.dimensions = { | ||
x: image.size.width / pixelsPerMeter, | ||
y: image.size.height / pixelsPerMeter | ||
}; | ||
} | ||
const dimensions = options.dimensions; | ||
const materialPlane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y); | ||
materialPlane.firstMaterial.diffuse.contents = image; | ||
materialPlane.firstMaterial.doubleSided = true; | ||
resolve(new ARImage(options, SCNNode.nodeWithGeometry(materialPlane), renderer)); | ||
}); | ||
} | ||
} | ||
exports.ARImage = ARImage; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARMaterialFactory = void 0; | ||
var ARMaterialFactory = (function () { | ||
function ARMaterialFactory() { | ||
} | ||
ARMaterialFactory.getMaterial = function (material) { | ||
class ARMaterialFactory { | ||
static getMaterial(material) { | ||
if (!material) { | ||
return null; | ||
} | ||
var mat = SCNMaterial.new(); | ||
const mat = SCNMaterial.new(); | ||
mat.lightingModelName = SCNLightingModelPhysicallyBased; | ||
@@ -23,8 +21,8 @@ if (typeof material === "string") { | ||
return mat; | ||
}; | ||
ARMaterialFactory.applyMaterialByColor = function (mat, material) { | ||
} | ||
static applyMaterialByColor(mat, material) { | ||
mat.diffuse.contents = material.ios; | ||
mat.specular.contents = material.ios; | ||
}; | ||
ARMaterialFactory.applyMaterialByString = function (mat, material) { | ||
} | ||
static applyMaterialByString(mat, material) { | ||
this.applyMaterialProperty(mat.diffuse, { | ||
@@ -34,4 +32,4 @@ contents: material, | ||
}); | ||
}; | ||
ARMaterialFactory.applyMaterialByARMaterial = function (mat, material) { | ||
} | ||
static applyMaterialByARMaterial(mat, material) { | ||
this.applyMaterialProperty(mat.diffuse, material.diffuse); | ||
@@ -51,4 +49,4 @@ this.applyMaterialProperty(mat.roughness, material.roughness); | ||
} | ||
}; | ||
ARMaterialFactory.applyMaterialProperty = function (scnMaterialProperty, materialProperty) { | ||
} | ||
static applyMaterialProperty(scnMaterialProperty, materialProperty) { | ||
if (materialProperty === undefined) { | ||
@@ -66,6 +64,6 @@ return; | ||
else { | ||
var prop = materialProperty; | ||
const prop = materialProperty; | ||
scnMaterialProperty.contents = UIImage.imageNamed(prop.contents); | ||
if (prop.wrapMode) { | ||
var wrapMode = ARMaterialFactory.getWrapMode(prop.wrapMode); | ||
const wrapMode = ARMaterialFactory.getWrapMode(prop.wrapMode); | ||
scnMaterialProperty.wrapS = wrapMode; | ||
@@ -79,4 +77,4 @@ scnMaterialProperty.wrapT = wrapMode; | ||
} | ||
}; | ||
ARMaterialFactory.getWrapMode = function (wrapMode) { | ||
} | ||
static getWrapMode(wrapMode) { | ||
if (wrapMode === "Mirror") { | ||
@@ -94,5 +92,4 @@ return 4; | ||
} | ||
}; | ||
return ARMaterialFactory; | ||
}()); | ||
} | ||
} | ||
exports.ARMaterialFactory = ARMaterialFactory; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARModel = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var ARModel = (function (_super) { | ||
__extends(ARModel, _super); | ||
function ARModel() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARModel.create = function (options) { | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
class ARModel extends arcommon_1.ARCommonNode { | ||
static create(options) { | ||
console.log(">> create ARModel"); | ||
return new Promise(function (resolve, reject) { | ||
return new Promise((resolve, reject) => { | ||
ARModel.download("https://github.com/EddyVerbruggen/nativescript-ar/raw/master/demo/app/App_Resources/iOS/Models.scnassets/Car.dae") | ||
.then(function (file) { | ||
var data = NSFileManager.defaultManager.contentsAtPath(file); | ||
var sceneSource = SCNSceneSource.sceneSourceWithDataOptions(data, null); | ||
var arr = sceneSource.identifiersOfEntriesWithClass(SCNMaterial.class()); | ||
.then((file) => { | ||
const data = NSFileManager.defaultManager.contentsAtPath(file); | ||
const sceneSource = SCNSceneSource.sceneSourceWithDataOptions(data, null); | ||
const arr = sceneSource.identifiersOfEntriesWithClass(SCNMaterial.class()); | ||
console.log(">> identifiers: " + arr.count); | ||
var modelScene = SCNScene.sceneWithURLOptionsError(NSURL.URLWithString(file), null); | ||
let modelScene = SCNScene.sceneWithURLOptionsError(NSURL.URLWithString(file), null); | ||
console.log(">> modelScene: " + modelScene); | ||
var nodeModel = options.childNodeName ? modelScene.rootNode.childNodeWithNameRecursively(options.childNodeName, true) : modelScene.rootNode; | ||
let nodeModel = options.childNodeName ? modelScene.rootNode.childNodeWithNameRecursively(options.childNodeName, true) : modelScene.rootNode; | ||
resolve(new ARModel(options, nodeModel)); | ||
}); | ||
}); | ||
}; | ||
ARModel.download = function (url) { | ||
return new Promise(function (resolve, reject) { | ||
core_1.Http.getFile(url).then(function (file) { | ||
} | ||
static download(url) { | ||
return new Promise((resolve, reject) => { | ||
core_1.Http.getFile(url).then((file) => { | ||
console.log(">>> downloaded to " + file.path); | ||
resolve(file.path); | ||
}, function (e) { return reject(e); }); | ||
}, (e) => reject(e)); | ||
}); | ||
}; | ||
return ARModel; | ||
}(arcommon_1.ARCommonNode)); | ||
} | ||
} | ||
exports.ARModel = ARModel; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARModel = void 0; | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARModel = (function (_super) { | ||
__extends(ARModel, _super); | ||
function ARModel() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARModel.create = function (options, renderer) { | ||
var modelScene = SCNScene.sceneNamed(options.name); | ||
var nodeModel; | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARModel extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, renderer) { | ||
let modelScene = SCNScene.sceneNamed(options.name); | ||
let nodeModel; | ||
if (options.childNodeName) { | ||
@@ -23,5 +19,4 @@ nodeModel = modelScene.rootNode.childNodeWithNameRecursively(options.childNodeName, true); | ||
return new ARModel(options, nodeModel.clone(), renderer); | ||
}; | ||
return ARModel; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
} | ||
exports.ARModel = ARModel; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARPlane = void 0; | ||
var ar_common_1 = require("../../ar-common"); | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARPlane = (function (_super) { | ||
__extends(ARPlane, _super); | ||
function ARPlane(options, node) { | ||
var _this = this; | ||
const ar_common_1 = require("../../ar-common"); | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARPlane extends arcommongeometry_1.ARCommonGeometryNode { | ||
constructor(options, node) { | ||
if (options) { | ||
_this = _super.call(this, options, node) || this; | ||
super(options, node); | ||
} | ||
return _this; | ||
} | ||
ARPlane.createExternal = function (options) { | ||
var dimensions = (typeof options.dimensions !== "number" ? options.dimensions : { | ||
static createExternal(options) { | ||
const dimensions = (typeof options.dimensions !== "number" ? options.dimensions : { | ||
x: options.dimensions, | ||
y: options.dimensions | ||
}); | ||
var plane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y); | ||
const plane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y); | ||
return new ARPlane(options, SCNNode.nodeWithGeometry(plane)); | ||
}; | ||
ARPlane.create = function (anchor, opacity, material) { | ||
var instance = new ARPlane(); | ||
} | ||
static create(anchor, opacity, material) { | ||
const instance = new ARPlane(); | ||
instance.ios = SCNNode.new(); | ||
instance.anchor = anchor; | ||
var anchorstr = "" + anchor; | ||
var extentStart = anchorstr.indexOf("extent=(") + "extent=(".length; | ||
var extentStr = anchorstr.substring(extentStart, anchorstr.indexOf(")", extentStart)); | ||
var extendParts = extentStr.split(" "); | ||
var planeHeight = 0.01; | ||
const anchorstr = "" + anchor; | ||
const extentStart = anchorstr.indexOf("extent=(") + "extent=(".length; | ||
const extentStr = anchorstr.substring(extentStart, anchorstr.indexOf(")", extentStart)); | ||
const extendParts = extentStr.split(" "); | ||
const planeHeight = 0.01; | ||
instance.planeGeometry = SCNBox.boxWithWidthHeightLengthChamferRadius(+extendParts[0], planeHeight, +extendParts[2], 0); | ||
var translationStart = anchorstr.indexOf("<translation=(") + "<translation=(".length; | ||
var translationStr = anchorstr.substring(translationStart, anchorstr.indexOf(")", translationStart)); | ||
var translationParts = translationStr.split(" "); | ||
const translationStart = anchorstr.indexOf("<translation=(") + "<translation=(".length; | ||
const translationStr = anchorstr.substring(translationStart, anchorstr.indexOf(")", translationStart)); | ||
const translationParts = translationStr.split(" "); | ||
instance.position = new ar_common_1.ARPosition(+translationParts[0], +translationParts[1], +translationParts[2]); | ||
instance.setMaterial(material, opacity); | ||
var planeNode = SCNNode.nodeWithGeometry(instance.planeGeometry); | ||
const planeNode = SCNNode.nodeWithGeometry(instance.planeGeometry); | ||
planeNode.position = { x: 0, y: -planeHeight / 2, z: 0 }; | ||
@@ -45,7 +42,7 @@ planeNode.physicsBody = SCNPhysicsBody.bodyWithTypeShape(2, SCNPhysicsShape.shapeWithGeometryOptions(instance.planeGeometry, null)); | ||
return instance; | ||
}; | ||
ARPlane.prototype.setMaterial = function (material, opacity) { | ||
var transparentMaterial = SCNMaterial.new(); | ||
} | ||
setMaterial(material, opacity) { | ||
const transparentMaterial = SCNMaterial.new(); | ||
transparentMaterial.diffuse.contents = UIColor.colorWithWhiteAlpha(1.0, 0.0); | ||
var materialArray = NSMutableArray.alloc().initWithCapacity(6); | ||
const materialArray = NSMutableArray.alloc().initWithCapacity(6); | ||
materialArray.addObject(transparentMaterial); | ||
@@ -64,27 +61,27 @@ materialArray.addObject(transparentMaterial); | ||
this.planeGeometry.materials = materialArray; | ||
}; | ||
ARPlane.prototype.update = function (anchor) { | ||
var anchorstr = "" + anchor; | ||
var extentStart = anchorstr.indexOf("extent=(") + "extent=(".length; | ||
var extentStr = anchorstr.substring(extentStart, anchorstr.indexOf(")", extentStart)); | ||
var extendParts = extentStr.split(" "); | ||
} | ||
update(anchor) { | ||
const anchorstr = "" + anchor; | ||
const extentStart = anchorstr.indexOf("extent=(") + "extent=(".length; | ||
const extentStr = anchorstr.substring(extentStart, anchorstr.indexOf(")", extentStart)); | ||
const extendParts = extentStr.split(" "); | ||
this.planeGeometry.width = +extendParts[0]; | ||
this.planeGeometry.length = +extendParts[2]; | ||
var centerStart = anchorstr.indexOf("center=(") + "center=(".length; | ||
var centerStr = anchorstr.substring(centerStart, anchorstr.indexOf(")", centerStart)); | ||
var centerParts = centerStr.split(" "); | ||
const centerStart = anchorstr.indexOf("center=(") + "center=(".length; | ||
const centerStr = anchorstr.substring(centerStart, anchorstr.indexOf(")", centerStart)); | ||
const centerParts = centerStr.split(" "); | ||
this.ios.position = { x: +centerParts[0], y: 0, z: +centerParts[2] }; | ||
var childNode = this.ios.childNodes.firstObject; | ||
const childNode = this.ios.childNodes.firstObject; | ||
childNode.physicsBody = SCNPhysicsBody.bodyWithTypeShape(2, SCNPhysicsShape.shapeWithGeometryOptions(this.planeGeometry, null)); | ||
ARPlane.setTextureScale(this.planeGeometry); | ||
}; | ||
ARPlane.prototype.remove = function () { | ||
} | ||
remove() { | ||
this.ios.removeFromParentNode(); | ||
}; | ||
ARPlane.setTextureScale = function (planeGeometry) { | ||
var width = planeGeometry.width; | ||
var height = planeGeometry.length; | ||
var material = planeGeometry.materials[4]; | ||
var scaleFactor = 1; | ||
var m = new SCNMatrix4(); | ||
} | ||
static setTextureScale(planeGeometry) { | ||
const width = planeGeometry.width; | ||
const height = planeGeometry.length; | ||
const material = planeGeometry.materials[4]; | ||
const scaleFactor = 1; | ||
const m = new SCNMatrix4(); | ||
m.m11 = width * scaleFactor; | ||
@@ -97,5 +94,4 @@ m.m22 = height * scaleFactor; | ||
material.normal.contentsTransform = m; | ||
}; | ||
return ARPlane; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
} | ||
exports.ARPlane = ARPlane; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARSphere = void 0; | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARSphere = (function (_super) { | ||
__extends(ARSphere, _super); | ||
function ARSphere() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ARSphere.create = function (options, renderer) { | ||
var sphere = SCNSphere.sphereWithRadius(options.radius); | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARSphere extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, renderer) { | ||
const sphere = SCNSphere.sphereWithRadius(options.radius); | ||
if (options.segmentCount) { | ||
@@ -16,5 +12,4 @@ sphere.segmentCount = options.segmentCount; | ||
return new ARSphere(options, SCNNode.nodeWithGeometry(sphere), renderer); | ||
}; | ||
return ARSphere; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
} | ||
exports.ARSphere = ARSphere; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARText = void 0; | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARText = (function (_super) { | ||
__extends(ARText, _super); | ||
function ARText() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARText extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, renderer) { | ||
const text = SCNText.textWithStringExtrusionDepth(options.text, options.depth || 0.0); | ||
return new ARText(options, SCNNode.nodeWithGeometry(text), renderer); | ||
} | ||
ARText.create = function (options, renderer) { | ||
var text = SCNText.textWithStringExtrusionDepth(options.text, options.depth || 0.0); | ||
return new ARText(options, SCNNode.nodeWithGeometry(text), renderer); | ||
}; | ||
return ARText; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
exports.ARText = ARText; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARTube = void 0; | ||
var arcommongeometry_1 = require("./arcommongeometry"); | ||
var ARTube = (function (_super) { | ||
__extends(ARTube, _super); | ||
function ARTube() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const arcommongeometry_1 = require("./arcommongeometry"); | ||
class ARTube extends arcommongeometry_1.ARCommonGeometryNode { | ||
static create(options, renderer) { | ||
const tube = SCNTube.tubeWithInnerRadiusOuterRadiusHeight(options.innerRadius, options.outerRadius, options.height); | ||
return new ARTube(options, SCNNode.nodeWithGeometry(tube), renderer); | ||
} | ||
ARTube.create = function (options, renderer) { | ||
var tube = SCNTube.tubeWithInnerRadiusOuterRadiusHeight(options.innerRadius, options.outerRadius, options.height); | ||
return new ARTube(options, SCNNode.nodeWithGeometry(tube), renderer); | ||
}; | ||
return ARTube; | ||
}(arcommongeometry_1.ARCommonGeometryNode)); | ||
} | ||
exports.ARTube = ARTube; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARUIView = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var pixelsPerMeter = 200 * core_1.Screen.mainScreen.scale; | ||
var main_queue = dispatch_get_current_queue(); | ||
var ARUIView = (function (_super) { | ||
__extends(ARUIView, _super); | ||
function ARUIView(options, sceneView, renderer) { | ||
var _this = this; | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
const pixelsPerMeter = 200 * core_1.Screen.mainScreen.scale; | ||
const main_queue = dispatch_get_current_queue(); | ||
class ARUIView extends arcommon_1.ARCommonNode { | ||
static create(options, sceneView, renderer) { | ||
return new ARUIView(options, sceneView, renderer); | ||
} | ||
constructor(options, sceneView, renderer) { | ||
try { | ||
var view_1 = options.view; | ||
var node_1 = SCNNode.node(); | ||
dispatch_async(main_queue, function () { | ||
if (view_1.parent) { | ||
view_1.ios.removeFromSuperview(); | ||
view_1.parent = null; | ||
const view = options.view; | ||
const node = SCNNode.node(); | ||
dispatch_async(main_queue, () => { | ||
if (view.parent) { | ||
view.ios.removeFromSuperview(); | ||
view.parent = null; | ||
} | ||
if (view_1 instanceof core_1.View && (!view_1.ios)) { | ||
view_1._setupUI({}); | ||
view_1.loadView(view_1); | ||
if (view instanceof core_1.View && (!view.ios)) { | ||
view._setupUI({}); | ||
view.loadView(view); | ||
} | ||
var nativeView = view_1.ios || view_1; | ||
view_1.measure(0, 0); | ||
const nativeView = view.ios || view; | ||
view.measure(0, 0); | ||
if (!options.dimensions) { | ||
options.dimensions = { | ||
x: view_1.getMeasuredWidth() / pixelsPerMeter, y: view_1.getMeasuredHeight() / pixelsPerMeter | ||
x: view.getMeasuredWidth() / pixelsPerMeter, y: view.getMeasuredHeight() / pixelsPerMeter | ||
}; | ||
} | ||
var cameraRatio = Math.max(sceneView.session.currentFrame.camera.imageResolution.height, sceneView.session.currentFrame.camera.imageResolution.width) / Math.min(sceneView.session.currentFrame.camera.imageResolution.height, sceneView.session.currentFrame.camera.imageResolution.width); | ||
var screenRatio = Math.max(core_1.Screen.mainScreen.heightPixels, core_1.Screen.mainScreen.widthPixels) / Math.min(core_1.Screen.mainScreen.heightPixels, core_1.Screen.mainScreen.widthPixels); | ||
var yStretchCompensation = (cameraRatio + screenRatio) / 2; | ||
const cameraRatio = Math.max(sceneView.session.currentFrame.camera.imageResolution.height, sceneView.session.currentFrame.camera.imageResolution.width) / Math.min(sceneView.session.currentFrame.camera.imageResolution.height, sceneView.session.currentFrame.camera.imageResolution.width); | ||
const screenRatio = Math.max(core_1.Screen.mainScreen.heightPixels, core_1.Screen.mainScreen.widthPixels) / Math.min(core_1.Screen.mainScreen.heightPixels, core_1.Screen.mainScreen.widthPixels); | ||
const yStretchCompensation = (cameraRatio + screenRatio) / 2; | ||
console.log("yStretchCompensation: " + yStretchCompensation); | ||
var dimensions = (typeof options.dimensions !== "number" ? options.dimensions : { | ||
const dimensions = (typeof options.dimensions !== "number" ? options.dimensions : { | ||
x: options.dimensions, | ||
y: options.dimensions * yStretchCompensation, | ||
}); | ||
var materialPlane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y * yStretchCompensation); | ||
const materialPlane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y * yStretchCompensation); | ||
materialPlane.cornerRadius = options.chamferRadius || 0; | ||
var planeViewController = ArPlaneViewController.alloc().initWithViewAndPlane(view_1, materialPlane); | ||
var planeNode = SCNNode.nodeWithGeometry(materialPlane); | ||
const planeViewController = ArPlaneViewController.alloc().initWithViewAndPlane(view, materialPlane); | ||
const planeNode = SCNNode.nodeWithGeometry(materialPlane); | ||
planeViewController.loadView(); | ||
@@ -54,3 +55,3 @@ planeNode.position = { | ||
}; | ||
node_1.eulerAngles = { | ||
node.eulerAngles = { | ||
x: 0, | ||
@@ -60,5 +61,5 @@ y: Math.PI, | ||
}; | ||
node_1.addChildNode(planeNode); | ||
node.addChildNode(planeNode); | ||
}); | ||
_this = _super.call(this, options, node_1, renderer) || this; | ||
super(options, node, renderer); | ||
} | ||
@@ -68,17 +69,8 @@ catch (e) { | ||
} | ||
return _this; | ||
} | ||
ARUIView.create = function (options, sceneView, renderer) { | ||
return new ARUIView(options, sceneView, renderer); | ||
}; | ||
return ARUIView; | ||
}(arcommon_1.ARCommonNode)); | ||
} | ||
exports.ARUIView = ARUIView; | ||
var ArPlaneViewController = (function (_super) { | ||
__extends(ArPlaneViewController, _super); | ||
function ArPlaneViewController() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ArPlaneViewController.prototype.initWithViewAndPlane = function (view, plane) { | ||
_super.prototype.init.call(this); | ||
class ArPlaneViewController extends UIViewController { | ||
initWithViewAndPlane(view, plane) { | ||
super.init(); | ||
this.childView = view; | ||
@@ -88,5 +80,5 @@ this.materialPlane = plane; | ||
return this; | ||
}; | ||
ArPlaneViewController.prototype.loadView = function () { | ||
_super.prototype.loadView.call(this); | ||
} | ||
loadView() { | ||
super.loadView(); | ||
try { | ||
@@ -99,6 +91,6 @@ if (!this.childView.ios) { | ||
this.view.addSubview(this.childView.ios); | ||
var frame = this.view.frame; | ||
var frameT = this.view.transform; | ||
var layout = this.childView.ios.frame; | ||
var layoutT = this.childView.ios.transform; | ||
const frame = this.view.frame; | ||
const frameT = this.view.transform; | ||
const layout = this.childView.ios.frame; | ||
const layoutT = this.childView.ios.transform; | ||
this.view.opaque = false; | ||
@@ -111,4 +103,3 @@ this.materialPlane.firstMaterial.diffuse.contents = this.view; | ||
} | ||
}; | ||
return ArPlaneViewController; | ||
}(UIViewController)); | ||
} | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ARVideo = void 0; | ||
var core_1 = require("@nativescript/core"); | ||
var arcommon_1 = require("./arcommon"); | ||
var ARVideo = (function (_super) { | ||
__extends(ARVideo, _super); | ||
function ARVideo() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const core_1 = require("@nativescript/core"); | ||
const arcommon_1 = require("./arcommon"); | ||
class ARVideo extends arcommon_1.ARCommonNode { | ||
isPlaying() { | ||
return this.videoPlayer && this.videoPlayer.timeControlStatus === 2; | ||
} | ||
ARVideo.prototype.isPlaying = function () { | ||
return this.videoPlayer && this.videoPlayer.timeControlStatus === 2; | ||
}; | ||
ARVideo.prototype.play = function () { | ||
play() { | ||
if (this.videoPlayer) { | ||
this.videoPlayer.play(); | ||
} | ||
}; | ||
ARVideo.prototype.pause = function () { | ||
} | ||
pause() { | ||
if (this.videoPlayer) { | ||
this.videoPlayer.pause(); | ||
} | ||
}; | ||
ARVideo.create = function (options, renderer) { | ||
var video = options.video; | ||
var dimensions = options.dimensions; | ||
} | ||
static create(options, renderer) { | ||
const video = options.video; | ||
let dimensions = options.dimensions; | ||
if (!options.dimensions) { | ||
@@ -33,5 +29,5 @@ dimensions = { | ||
} | ||
var materialPlane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y); | ||
var nativeUrl; | ||
var videoPlayer; | ||
const materialPlane = SCNPlane.planeWithWidthHeight(dimensions.x, dimensions.y); | ||
let nativeUrl; | ||
let videoPlayer; | ||
if (typeof video === "string") { | ||
@@ -43,9 +39,9 @@ if (video.indexOf("://") >= 0) { | ||
try { | ||
var parts = video.split('/'); | ||
var name_1 = parts.pop(); | ||
var dir = parts.join('/'); | ||
var nameParts = name_1.split('.'); | ||
var ext = nameParts.pop(); | ||
name_1 = nameParts.join('.'); | ||
nativeUrl = NSBundle.mainBundle.URLForResourceWithExtensionSubdirectory(name_1, ext, dir); | ||
let parts = video.split('/'); | ||
let name = parts.pop(); | ||
let dir = parts.join('/'); | ||
let nameParts = name.split('.'); | ||
let ext = nameParts.pop(); | ||
name = nameParts.join('.'); | ||
nativeUrl = NSBundle.mainBundle.URLForResourceWithExtensionSubdirectory(name, ext, dir); | ||
} | ||
@@ -80,3 +76,3 @@ catch (e) { | ||
if (options.loop !== false) { | ||
var AVPlayerItemDidPlayToEndTimeNotificationObserver = core_1.Application.ios.addNotificationObserver(AVPlayerItemDidPlayToEndTimeNotification, function (notification) { | ||
const AVPlayerItemDidPlayToEndTimeNotificationObserver = core_1.Application.ios.addNotificationObserver(AVPlayerItemDidPlayToEndTimeNotification, (notification) => { | ||
if (videoPlayer.currentItem && videoPlayer.currentItem === notification.object) { | ||
@@ -91,9 +87,8 @@ videoPlayer.seekToTime(CMTimeMake(5, 100)); | ||
} | ||
var node = SCNNode.nodeWithGeometry(materialPlane); | ||
var arVideo = new ARVideo(options, node, renderer); | ||
const node = SCNNode.nodeWithGeometry(materialPlane); | ||
const arVideo = new ARVideo(options, node, renderer); | ||
arVideo.videoPlayer = videoPlayer; | ||
return arVideo; | ||
}; | ||
return ARVideo; | ||
}(arcommon_1.ARCommonNode)); | ||
} | ||
} | ||
exports.ARVideo = ARVideo; |
{ | ||
"name": "@bezlepkin/nativescript-ar", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "NativeScript Augmented Reality plugin. ARKit on iOS and (with the help of Sceneform) ARCore on Android.", | ||
@@ -5,0 +5,0 @@ "main": "ar", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
166748
95.26%42
27.27%3996
118.96%1
Infinity%