Skip to content

Commit 4d6b02a

Browse files
committed
Support for more mathematical expressions
1 parent e4ced84 commit 4d6b02a

File tree

11 files changed

+339
-36
lines changed

11 files changed

+339
-36
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Change Log
22

3+
## [4.5.0]
4+
5+
增加:
6+
7+
Added:
8+
9+
- 支持更多数学表达式
10+
11+
Support for more mathematical expressions
12+
13+
优化:
14+
15+
Improved:
16+
17+
- 找不到包时的提示更友好
18+
19+
More user-friendly prompts when packages are not found
20+
321
## [4.4.0]
422

523
增加:

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,17 @@ There are three installation methods:
121121

122122
## Release Notes
123123

124-
### 4.4.0
124+
### 4.5.0
125+
126+
Added:
127+
128+
- Support for more mathematical expressions
129+
130+
Improved:
131+
132+
- More user-friendly prompts when packages are not found
133+
134+
### 4.4.x
125135

126136
Added:
127137

README_zh-CN.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,17 @@ A VSCode extension for visualizing URDF files and xacro files.
122122

123123
## Release Notes
124124

125-
### 4.4.0
125+
### 4.5.0
126+
127+
增加:
128+
129+
- 支持更多数学表达式
130+
131+
优化:
132+
133+
- 找不到包时的提示更友好
134+
135+
### 4.4.x
126136

127137
增加:
128138

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default [{
1010

1111
languageOptions: {
1212
parser: tsParser,
13-
ecmaVersion: 2020,
13+
ecmaVersion: 2022,
1414
sourceType: "module",
1515
},
1616

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/MorningFrog/urdf-visualizer"
88
},
9-
"version": "4.4.0",
9+
"version": "4.5.0",
1010
"publisher": "morningfrog",
1111
"engines": {
1212
"vscode": "^1.70.0"

src/extension.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import {
99
isUrdfOrXacroFile,
1010
isXacroFile,
1111
} from "./extension_utils";
12-
const { XacroParser } = require("xacro-parser");
13-
const { JSDOM } = require("jsdom");
1412
const { XMLSerializer, XMLDocument } = require("xmldom");
15-
16-
global.DOMParser = new JSDOM().window.DOMParser;
13+
import { xacroParser } from "./xacro_parser_instance";
1714

1815
// This method is called when your extension is activated
1916
// Your extension is activated the very first time the command is executed
@@ -31,20 +28,15 @@ export function activate(context: vscode.ExtensionContext) {
3128

3229
let uriPrefix: string | null = null; // 保存当前文件的 URI 前缀
3330

34-
const xacroParser = new XacroParser(); // xacro 解析器
3531
const serializer = new XMLSerializer(); // XML 序列化器
3632

37-
// 在 xacroParser 中使用 fs 读取文件内容
38-
xacroParser.getFileContents = (filePath: string) => {
39-
return fs.readFileSync(filePath, { encoding: "utf8" });
40-
};
4133
// 设置 ROS 功能包路径
4234
xacroParser.rospackCommands = {
4335
find: function (pkg: string) {
4436
if (packagesResolved && packagesResolved[pkg]) {
4537
return packagesResolved[pkg];
4638
} else {
47-
return "";
39+
throw new Error(`Package "${pkg}" not found`);
4840
}
4941
},
5042
};
@@ -70,6 +62,7 @@ export function activate(context: vscode.ExtensionContext) {
7062
.catch((error: { message: string }) => {
7163
vscode.window.showErrorMessage(error.message);
7264
})
65+
// @ts-ignore
7366
.then((data: XMLDocument) => {
7467
sendURDF(serializer.serializeToString(data), workingPath);
7568
});

src/webview/module_urdf.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,17 @@ export class ModuleURDF {
156156
this.loaderURDF.parseVisual = true;
157157

158158
// 设置 manager 报错时的处理
159-
this.manager.onError = (url: string) => {
160-
// 删除 url 中 `vscode-cdn.net` 及其之前的部分
161-
const url_parts = url.split("vscode-cdn.net");
162-
if (url_parts.length > 1) {
163-
url = url_parts[1];
164-
}
165-
vscode.postMessage({
166-
type: "error",
167-
message: `Failed to load ${url}`,
168-
});
169-
};
159+
// this.manager.onError = (url: string) => {
160+
// // 删除 url 中 `vscode-cdn.net` 及其之前的部分
161+
// const url_parts = url.split(this.uriPrefix);
162+
// if (url_parts.length > 1) {
163+
// url = url_parts[1];
164+
// }
165+
// vscode.postMessage({
166+
// type: "error",
167+
// message: `Failed to load ${url}`,
168+
// });
169+
// };
170170

171171
// 设置资源处理函数
172172
this.manager.setURLModifier((url: string): string => {
@@ -695,6 +695,10 @@ export class ModuleURDF {
695695
}
696696

697697
set packages(packages: { [key: string]: string }) {
698+
// 去除末尾的 `/` 或 `\` 后导入 packages
699+
for (const key in packages) {
700+
packages[key] = packages[key].trimEnd().replace(/[\\/]+$/, "");
701+
}
698702
this.loaderURDF.packages = packages;
699703
}
700704

src/webview/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Main {
3535
camera: THREE.PerspectiveCamera;
3636
renderer: THREE.WebGLRenderer;
3737
dirLight: THREE.DirectionalLight;
38-
ambientLight: THREE.HemisphereLight;
38+
ambientLight: THREE.AmbientLight;
3939
controls: OrbitControls;
4040

4141
// 资源路径前缀

src/webview/threejs_tools.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@ export function createScene() {
2929

3030
const dirLight = new THREE.DirectionalLight(0xffffff, Math.PI);
3131
dirLight.position.set(4, 10, 10);
32-
dirLight.shadow.mapSize.width = 2048;
33-
dirLight.shadow.mapSize.height = 2048;
34-
dirLight.shadow.normalBias = 0.001;
3532
dirLight.castShadow = true;
3633
scene.add(dirLight);
3734
scene.add(dirLight.target);
3835

39-
const ambientLight = new THREE.HemisphereLight("#fff", "#000");
40-
ambientLight.groundColor.lerp(ambientLight.color, 0.5 * Math.PI);
41-
ambientLight.intensity = 0.5;
42-
ambientLight.position.set(0, 0, 1);
36+
const ambientLight = new THREE.AmbientLight("#fff", 1.0);
4337
scene.add(ambientLight);
4438

4539
const controls = new OrbitControls(camera, renderer.domElement);

0 commit comments

Comments
 (0)