Skip to content

Commit

Permalink
Update babylon_ros (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
polyhobbyist authored Apr 26, 2023
1 parent 8227864 commit d83f64c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
"test-compile": "npm run webpack"
},
"dependencies": {
"@polyhobbyist/babylon_ros": "^0.0.2",
"@polyhobbyist/babylon_ros": "^0.0.3",
"@polyhobbyist/babylon-collada-loader": "^0.0.3",
"@vscode/debugadapter": "^1.59.0",
"@vscode/extension-telemetry": "^0.6.2",
Expand Down
51 changes: 33 additions & 18 deletions src/urdfPreview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default class URDFPreview
private async loadResource() {
this._processing = true;

var packagesNotFound = [];
var urdfText;
try {
urdfText = await xacro(this._resource.fsPath);
Expand All @@ -104,24 +105,31 @@ export default class URDFPreview
var pattern = /package:\/\/(.*?)\//g;
var match;
while (match = pattern.exec(urdfText)) {
var packagePath = await packageMap[match[1]]();
if (packagePath.charAt(0) === '/') {
// inside of mesh re \source, the loader attempts to concatinate the base uri with the new path. It first checks to see if the
// base path has a /, if not it adds it.
// We are attempting to use a protocol handler as the base path - which causes this to fail.
// basepath - vscode-webview-resource:
// full path - /home/test/ros
// vscode-webview-resource://home/test/ros.
// It should be vscode-webview-resource:/home/test/ros.
// So remove the first char.

packagePath = packagePath.substr(1);
if (packageMap.hasOwnProperty(match[1]) == false) {
if (packagesNotFound.indexOf(match[1]) == -1) {
extension.outputChannel.appendLine(`Package ${match[1]} not found in workspace.`);
packagesNotFound.push(match[1]);
}
} else {
var packagePath = await packageMap[match[1]]();
if (packagePath.charAt(0) === '/') {
// inside of mesh re \source, the loader attempts to concatinate the base uri with the new path. It first checks to see if the
// base path has a /, if not it adds it.
// We are attempting to use a protocol handler as the base path - which causes this to fail.
// basepath - vscode-webview-resource:
// full path - /home/test/ros
// vscode-webview-resource://home/test/ros.
// It should be vscode-webview-resource:/home/test/ros.
// So remove the first char.

packagePath = packagePath.substr(1);
}
let normPath = path.normalize(packagePath);
let vsPath = vscode.Uri.file(normPath);
let newUri = this._webview.webview.asWebviewUri(vsPath);

urdfText = urdfText.replace('package://' + match[1], newUri);
}
let normPath = path.normalize(packagePath);
let vsPath = vscode.Uri.file(normPath);
let newUri = this._webview.webview.asWebviewUri(vsPath);

urdfText = urdfText.replace('package://' + match[1], newUri);
}
}

Expand All @@ -137,6 +145,13 @@ export default class URDFPreview
} catch (err) {
vscode.window.showErrorMessage(err.message);
}

if (packagesNotFound.length > 0) {
var packagesNotFoundList = packagesNotFound.join('\n');

packagesNotFoundList += '\n\nNOTE: If this occurs at startup, please try saving the open file to refresh.';
vscode.window.showErrorMessage("The following packages were not found in the workspace:\n" + packagesNotFoundList);
}
}

public static async revive(
Expand Down Expand Up @@ -240,7 +255,7 @@ export default class URDFPreview
touch-action: none;
}
</style>
<title>Hello World!</title>
<title>URDF Preview</title>
</head>
<body>
<canvas id="renderCanvas" touch-action="none"></canvas>
Expand Down

0 comments on commit d83f64c

Please sign in to comment.