Loading PCD files using NPM and Three.js - three.js

I am new with Three.js and I'm struggling to import a PCD file into the scene and I would need some help if possible.
I'm using node.module and I've installed "pcd-format" using npm.
Here is an image of my workspace:
enter image description here
I would like to go with as simple code as possible for the beginning, without using some complex packages in order to understand the principles.
Thanks

Well, I'll answer to my question since I got help on similar issue on the other platform. Here's what I've done:
In the Terminal in Visual Studio Code: npm create vite , installed "Vanilla" framework, initialized a new project "my-project".
After creating "my-project" folder I got files such as main.js , package.json , etc.
From "my-project" in Terminal I installed three: npm install three and npm run dev to serve my app on localhost:3000
Then I imported PCDLoader and the script for loading a PCD model that I copied from three.js/docs (https://threejs.org/docs/index.html?q=load#examples/en/loaders/PCDLoader):
document.querySelector('#app').innerHTML = `
<h1>Ciao</h1>
Documentation
`
import { PCDLoader } from 'three/examples/jsm/loaders/PCDLoader'
console.log(PCDLoader)
const loader = new PCDLoader();
loader.load(
// resource URL
'pointcloud.pcd',
// called when the resource is loaded
function ( mesh ) {
scene.add( mesh );
},
// called when loading is in progresses
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
It now works except that the app crashes when I debug and it says that DevTools was disconnected from the page....

Related

How to use Microsoft Graph Toolkit with SPFX 1.15.2

I created a new SPFX solution with yo. Then I followed this guide:
Installed with
npm install #microsoft/mgt-spfx
and
npm install #microsoft/mgt-react
Then I changed the init method in the webpart.ts file to following code
protected onInit(): Promise<void> {
if (!Providers.globalProvider) {
Providers.globalProvider = new SharePointProvider(this.context);
}
return super.onInit();
}
Added the import
import { SharePointProvider, Providers } from '#microsoft/mgt-spfx';
In the tsx component file I changed the render to
public render(): React.ReactElement<IPeoplePickerTestProps> {
return (
<div>
Test
<Person personQuery="me" view={ViewType.image}></Person>
</div>
);
}
and added the import
import { Person, ViewType } from '#microsoft/mgt-react/dist/es6';
Then I uploaded the latest toolkit spfx package (got it here) to the app catalog (deployed to all sites), builded my solution (gulp bundle --ship, gulp package-solution --ship) and uploaded it to the app catalog. Created a new site collection and installed my solution. Its not working at all. There is nothing rendered except the text "Test". In the console I can see following error which does not really help me:
Toolkit version: 2.6.1
SPFX version: 1.15.2
Tested on different tenants.
I got similar issue, try importing from
#microsoft/mgt-react/dist/es6/spfx
so:
import { Person } from '#microsoft/mgt-react/dist/es6/spfx';
import { ViewType } from '#microsoft/mgt-spfx';
Hope that helps

Setassign PDF in Laravel Vapor Amazon Lambda

I'm trying to import a PDF from storage to print values using FPDF and FPDI to download the PDF with the values. My function works perfectly on my local system but fails to open on my staging environment hosted on AWS Lambda. If anyone could assist, it would help me so much. It's so important that I get this done. Even if you could point me in the right direction, I would greatly appreciate it.
Controller
use setasign\FpdiProtection\FpdiProtection;
use setasign\Fpdi\Fpdi;
public function medical_pdf()
{
// initiate FPDI
$pdf = new FpdiProtection();
// set title
$title = "Outsurance Medical Questionnaire";
$pdf->SetTitle($title);
// add a page
$pdf->AddPage();
// set password
$pdf->SetProtection(array(), 'BlueinDecember#2021');
// set the source file
$pdf->setSourceFile(public_path('/PDF/Generic OutSurance SMR .pdf'));
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
$pdf->useTemplate($tplIdx, -0, -0, 200);
$pdf->Output('D',$title.'.pdf',);
}

Trying to open an app in the Play Store (android)

I'm trying to direct the user to the play store.
import app = require("application");
var intent = new android.content.Intent("android.intent.action.VIEW" );
intent.setData( "market://details?id=MY.APP.LINK" );
app.android.currentContext.startActivity(intent);
The above isn't working!
I think the problem has to do with my translation from Java code to something {N} can use.
#Brad Martin gave the answer in comments but I'm adding this for readability, as I needed this snippet. Didn't try the iOS part yet.
Here is the code I used, with TypeScript.
First, add those lines in import
import * as application from "application";
import * as Utility from "utils/utils";
declare var android: any;
Then, you can use a function like this one for Android
gotoPlayStore() {
let androidPackageName = application.android.packageName;
let uri = android.net.Uri.parse("market://details?id=" + androidPackageName);
let myAppLinkToMarket = new android.content.Intent(android.content.Intent.ACTION_VIEW, uri);
// Launch the PlayStore
application.android.foregroundActivity.startActivity(myAppLinkToMarket);
}
You can use this code for iOS devices
gotoAppStore() {
let appStore = "";
appStore = "itms-apps://itunes.apple.com/en/app/id" + myAppId;
Utility.openUrl(appStore);
}
This code is based on the plugin nativescript-rating from Nic Raboy and this particular file : https://github.com/nraboy/nativescript-ratings/blob/master/ratings.ts
You may get this error on Android : ERROR Error: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=your.package.id } , but it's working on real device, as Play Store application is running on it.
Here's what worked for me:
try
{
let uri = android.net.Uri.parse( "market://details?id=com.company" );
var intent = new android.content.Intent( android.content.Intent.ACTION_VIEW, uri );
application.android.foregroundActivity.startActivity( intent );
}
catch ( e2 )
{
console.error( "Error =" + e2.message + "=" );
}

Auto-updates to Electron

I'm looking to deploy an auto-update feature to an Electron installation that I have, however I am finding it difficult to find any resources on the web.
I've built a self contained application using Adobe Air before and it seemed to be a lot easier writing update code that effectively checked a url and automatically downloaded and installed the update across Windows and MAC OSX.
I am currently using the electron-boilerplate for ease of build.
I have a few questions:
How do I debug the auto update feature? Do I setup a local connection and test through that using a local Node server or can I use any web server?
In terms of signing the application I am only looking to run apps on MAC OSX and particularly Windows. Do I have to sign the applications in order to run auto-updates? (I managed to do this with Adobe Air using a local certificate.
Are there any good resources that detail how to implement the auto-update feature? As I'm having difficulty finding some good documentation on how to do this.
I am also new to Electron but I think there is no simple auto-update from electron-boilerplate (which I also use). Electron's auto-updater uses Squirrel.Windows installer which you also need to implement into your solution in order to use it.
I am currently trying to use this:
https://www.npmjs.com/package/electron-installer-squirrel-windows
And more info can be found here:
https://github.com/atom/electron/blob/master/docs/api/auto-updater.md
https://github.com/squirrel/squirrel.windows
EDIT: I just opened the project to try it for a while and it looks it works. Its pretty straightforward. These are pieces from my gulpfile.
In current configuration, I use electron-packager to create a package.
var packager = require('electron-packager')
var createPackage = function () {
var deferred = Q.defer();
packager({
//OPTIONS
}, function done(err, appPath) {
if (err) {
gulpUtil.log(err);
}
deferred.resolve();
});
return deferred.promise;
};
Then I create an installer with electron-installer-squirrel-windows.
var squirrelBuilder = require('electron-installer-squirrel-windows');
var createInstaller = function () {
var deferred = Q.defer();
squirrelBuilder({
// OPTIONS
}, function (err) {
if (err)
gulpUtil.log(err);
deferred.resolve();
});
return deferred.promise;
}
Also you need to add some code for the Squirrel to your electron background/main code. I used a template electron-squirrel-startup.
if(require('electron-squirrel-startup')) return;
The whole thing is described on the electron-installer-squirrel-windows npm documentation mentioned above. Looks like the bit of documentation is enough to make it start.
Now I am working on with electron branding through Squirrel and with creating appropriate gulp scripts for automation.
You could also use standard Electron's autoUpdater module on OS X and my simple port of it for Windows: https://www.npmjs.com/package/electron-windows-updater
I followed this tutorial and got it working with my electron app although it needs to be signed to work so you would need:
certificateFile: './path/to/cert.pfx'
In the task config.
and:
"build": {
"win": {
"certificateFile": "./path/to/cert.pfx",
"certificatePassword": "password"
}
},
In the package.json
Are there any good resources that detail how to implement the auto-update feature? As I'm having difficulty finding some good documentation on how to do this.
You don't have to implement it by yourself. You can use the provided autoUpdater by Electron and just set a feedUrl. You need a server that provides the update information compliant to the Squirrel protocol.
There are a couple of self-hosted ones (https://electronjs.org/docs/tutorial/updates#deploying-an-update-server) or a hosted service like https://www.update.rocks
Question 1:
I use Postman to validate that my auto-update server URLs return the response I am expecting. When I know that the URLs provide the expected results, I know I can use those URLs within the Electron's Auto Updater of my Application.
Example of testing Mac endpoint with Postman:
Request:
https://my-server.com/api/macupdates/checkforupdate.php?appversion=1.0.5&cpuarchitecture=x64
JSON Response when there is an update available:
{
"url": "https:/my-server.com/updates/darwin/x64/my-electron=app-x64-1.1.0.zip",
"name": "1.1.0",
"pub_date": "2021-07-03T15:17:12+00:00"
}
Question 2:
Yes, your Electron App must be code signed to use the auto-update feature on Mac. On Windows I'm not sure because my Windows Electron app is code signed and I did not try without it. Though it is recommended that you sign your app even if the auto-update could work without it (not only for security reasons but mainly because otherwise your users will get scary danger warnings from Windows when they install your app for the first time and they might just delete it right away).
Question 3:
For good documentation, you should start with the official Electron Auto Updater documentation, as of 2021-07-07 it is really good.
The hard part, is figuring out how to make things work for Mac. For Windows it's a matter of minutes and you are done. In fact...
For Windows auto-update, it is easy to setup - you just have to put the RELEASES and nupkg files on a server and then use that URL as the FeedURL within your Electron App's autoUpdater. So if your app's update files are located at https://my-server.com/updates/win32/x64/ - you would point the Electron Auto Updater to that URL, that's it.
For Mac auto-update, you need to manually specify the absolute URL of the latest Electron App .zip file to the Electron autoUpdater. So, in order to make the Mac autoUpdater work, you will need to have a way to get a JSON response in a very specific format. Sadly, you can't just put your Electron App's files on your server and expect it to work with Mac just like that. Instead, the autoUpdater needs a URL that will return the aforementioned JSON response. So to do that, you need to pass Electron's Auto Updater feedURL the URL that will be able to return this expected kind of JSON response.
The way you achieve this can be anything but I use PHP just because that's the server I already paid for.
So in summary, with Mac, even if your files are located at https://my-server.com/updates/darwin/x64/ - you will not provide that URL to Electron's Auto Updater FeedURL. Instead will provide another URL which returns the expected JSON response.
Here's an example of my main.js file for the Electron main process of my App:
// main.js (Electron main process)
function registerAutoUpdater() {
const appVersion = app.getVersion();
const os = require('os');
const cpuArchitecture = os.arch();
const domain = 'https://my-server.com';
const windowsURL = `${domain}/updates/win32/x64`;
const macURL = `${domain}/api/macupdates/checkforupdate.php?appversion=${appVersion}&cpuarchitecture=${cpuArchitecture}`;
//init the autoUpdater with proper update feed URL
const autoUpdateURL = `${isMac ? macURL : windowsURL}`;
autoUpdater.setFeedURL({url: autoUpdateURL});
log.info('Registered autoUpdateURL = ' + (isMac ? 'macURL' : 'windowsURL'));
//initial checkForUpdates
autoUpdater.checkForUpdates();
//Automatic 2-hours interval loop checkForUpdates
setInterval(() => {
autoUpdater.checkForUpdates();
}, 7200000);
}
And here's an example of the checkforupdate.php file that returns the expected JSON response back to the Electron Auto Updater:
<?php
//FD Electron App Mac auto update API endpoint.
// The way Squirrel.Mac works is by checking a given API endpoint to see if there is a new version.
// If there is no new version, the endpoint should return HTTP 204. If there is a new version,
// however, it will expect a HTTP 200 JSON-formatted response, containing a url to a .zip file:
// https://github.com/Squirrel/Squirrel.Mac#server-support
$clientAppVersion = $_GET["appversion"] ?? null;
if (!isValidVersionString($clientAppVersion)) {
http_response_code(204);
exit();
}
$clientCpuArchitecture = $_GET["cpuarchitecture"] ?? null;
$latestVersionInfo = getLatestVersionInfo($clientAppVersion, $clientCpuArchitecture);
if (!isset($latestVersionInfo["versionNumber"])) {
http_response_code(204);
exit();
}
// Real logic starts here when basics did not fail
$isUpdateVailable = isUpdateAvailable($clientAppVersion, $latestVersionInfo["versionNumber"]);
if ($isUpdateVailable) {
http_response_code(200);
header('Content-Type: application/json;charset=utf-8');
$jsonResponse = array(
"url" => $latestVersionInfo["directZipFileURL"],
"name" => $latestVersionInfo["versionNumber"],
"pub_date" => date('c', $latestVersionInfo["createdAtUnixTimeStamp"]),
);
echo json_encode($jsonResponse);
} else {
//no update: must respond with a status code of 204 No Content.
http_response_code(204);
}
exit();
// End of execution.
// Everything bellow here are function declarations.
function getLatestVersionInfo($clientAppVersion, $clientCpuArchitecture): array {
// override path if client requests an arm64 build
if ($clientCpuArchitecture === 'arm64') {
$directory = "../../updates/darwin/arm64/";
$baseUrl = "https://my-server.com/updates/darwin/arm64/";
} else if (!$clientCpuArchitecture || $clientCpuArchitecture === 'x64') {
$directory = "../../updates/darwin/";
$baseUrl = "https://my-server.com/updates/darwin/";
}
// default name with version 0.0.0 avoids failing
$latestVersionFileName = "Finance D - Tenue de livres-darwin-x64-0.0.0.zip";
$arrayOfFiles = scandir($directory);
foreach ($arrayOfFiles as $file) {
if (is_file($directory . $file)) {
$serverFileVersion = getVersionNumberFromFileName($file);
if (isVersionNumberGreater($serverFileVersion, $clientAppVersion)) {
$latestVersionFileName = $file;
}
}
}
return array(
"versionNumber" => getVersionNumberFromFileName($latestVersionFileName),
"directZipFileURL" => $baseUrl . rawurlencode($latestVersionFileName),
"createdAtUnixTimeStamp" => filemtime(realpath($directory . $latestVersionFileName))
);
}
function isUpdateAvailable($clientVersion, $serverVersion): bool {
return
isValidVersionString($clientVersion) &&
isValidVersionString($serverVersion) &&
isVersionNumberGreater($serverVersion, $clientVersion);
}
function getVersionNumberFromFileName($fileName) {
// extract the version number with regEx replacement
return preg_replace("/Finance D - Tenue de livres-darwin-(x64|arm64)-|\.zip/", "", $fileName);
}
function removeAllNonDigits($semanticVersionString) {
// use regex replacement to keep only numeric values in the semantic version string
return preg_replace("/\D+/", "", $semanticVersionString);
}
function isVersionNumberGreater($serverFileVersion, $clientFileVersion): bool {
// receives two semantic versions (1.0.4) and compares their numeric value (104)
// true when server version is greater than client version (105 > 104)
return removeAllNonDigits($serverFileVersion) > removeAllNonDigits($clientFileVersion);
}
function isValidVersionString($versionString) {
// true when matches semantic version numbering: 0.0.0
return preg_match("/\d\.\d\.\d/", $versionString);
}

ReferenceError: "BarSeriesImpl" is not defined

My report works fine in BIRT- it shows some Bar chart graphic.
But when I import in some system (IBM maximo) I am getting this error instead of displaying the bar chart:
ReferenceError: "BarSeriesImpl" is not defined. at line 8 of chart script:''
I used this script to show me some values on Bar chart.
importPackage( Packages.java.util );
importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
function afterDataSetFilled(series, dataSet, icsc)
{
if( series.getClass() == BarSeriesImpl ){
var inv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("IN"));
var outv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("OUT"));
var canv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("CANCELED"));
var narray1 = new ArrayList( );
narray1.add(inv);
narray1.add(outv);
narray1.add(canv);
dataSet.setValues(narray1);
}else{
var catArray = new ArrayList();
catArray.add("IN");
catArray.add("OUT");
catArray.add("CANCELED");
dataSet.setValues(catArray);
}
}
How to solve this? Does I have to import somehow this class in my system or ..?
Thank you
I know I'm resurrecting an old question but this just caught my eye because it was similar to another post I answered this week. I think you might be missing org.eclipse.birt.chart.model.type.impl.BarSeriesImp in the systems that you are getting this error message. I think if you add the BIRT runtime jars to the lib path then it should resolve that error.

Resources