BabylonJS / Editor

Community managed visual editor for Babylon.js
http://editor.babylonjs.com/
813 stars 232 forks source link

Propose a way to export scripts #161

Closed sprhawk closed 3 years ago

sprhawk commented 4 years ago

I'm woking on a project built with Webpack + typescript, and I want to setup most of scene based on export of Babylon.js Editor.

However I see there is no scripts is exported by the Editor, the scripts are saved inside project.editorproject file. And It also depends on global babylonjs which is not flexible to support es6 style code structure.

I propose a way to export scripts to solve above problem.

  1. each script will have two parts: foo.ts and foo.deps.ts, foo.ts contains all logic code with first line as import * from "./foo.deps.ts";, and in foo.deps.ts contains all required import lines with export symbols, such as export { Mesh } from "babylonjs".
  2. when adding new scripts, the editor generates both files from its templates.
  3. when exporting, user can select whether editor should export *.deps.ts.
  4. If didn't choose to export .deps.ts, the users should provide own .deps.ts files to fit in es6 types import, such as export { Mesh } from '@babylonjs/core';
  5. in user's own project, he/she should import these scripts manually.
julien-moreau commented 4 years ago

Hey @sprhawk thanks a lot for the help. Indeed, the @babylonjs/* modules are now a problem for the editor right now and I’m focusing on. You proposition looks really good. What I purpose is, to help me: can you share a repository with what you are intended to have in the generated template? With a minimalist web pack config? I mean a working repository I can « copy » to fit the feature. That would help me a lot !

Thanks again and will fix that ASAP :)

sprhawk commented 4 years ago

@julien-moreau Hi, what do you think of this repo

julien-moreau commented 4 years ago

Yeah! The one I’m working on :) Can you create at least a new git branch and create all the files you mentioned as an example to make we pack building well and help me to see the architecture you also mentioned?

sprhawk commented 4 years ago

@julien-moreau Sorry,I didn't understand well. Could you explain in detail?

julien-moreau commented 4 years ago

No need, i finally understood well your request :)

julien-moreau commented 4 years ago

You can find the preview version here: http://editor.babylonjs.com/electron/preview/BabylonJS%20Editor%20Setup%203.2.1-beta.4.exe

When you export, don't forget to import "./scripts" in your game.ts file :)

julien-moreau commented 3 years ago

Done in the V4! Now using @babylonjs/* modules