|
@@ -28,6 +28,7 @@ import { SerializationHelper } from '../../Misc/decorators';
|
|
|
import { TextureBlock } from './Blocks/Dual/textureBlock';
|
|
|
import { ReflectionTextureBlock } from './Blocks/Dual/reflectionTextureBlock';
|
|
|
import { EffectFallbacks } from '../effectFallbacks';
|
|
|
+import { WebRequest } from '../../Misc/webRequest';
|
|
|
|
|
|
// declare NODEEDITOR namespace for compilation issue
|
|
|
declare var NODEEDITOR: any;
|
|
@@ -43,6 +44,10 @@ export interface INodeMaterialEditorOptions {
|
|
|
|
|
|
/** @hidden */
|
|
|
export class NodeMaterialDefines extends MaterialDefines implements IImageProcessingConfigurationDefines {
|
|
|
+ public NORMAL = false;
|
|
|
+ public TANGENT = false;
|
|
|
+ public UV1 = false;
|
|
|
+
|
|
|
/** BONES */
|
|
|
public NUM_BONE_INFLUENCERS = 0;
|
|
|
public BonesPerMesh = 0;
|
|
@@ -114,9 +119,12 @@ export class NodeMaterial extends PushMaterial {
|
|
|
private _optimizers = new Array<NodeMaterialOptimizer>();
|
|
|
private _animationFrame = -1;
|
|
|
|
|
|
- /** Define the URl to load node editor script */
|
|
|
+ /** Define the Url to load node editor script */
|
|
|
public static EditorURL = `https://unpkg.com/babylonjs-node-editor@${Engine.Version}/babylon.nodeEditor.js`;
|
|
|
|
|
|
+ /** Define the Url to load snippets */
|
|
|
+ public static SnippetUrl = "https://snippet.babylonjs.com";
|
|
|
+
|
|
|
private BJSNODEMATERIALEDITOR = this._getGlobalNodeMaterialEditor();
|
|
|
|
|
|
/** Get the inspector from bundle or global */
|
|
@@ -1293,6 +1301,41 @@ export class NodeMaterial extends PushMaterial {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Creates a node material from a snippet saved by the node material editor
|
|
|
+ * @param snippetId defines the snippet to load
|
|
|
+ * @param scene defines the hosting scene
|
|
|
+ * @param rootUrl defines the root URL to use to load textures and relative dependencies
|
|
|
+ * @returns a promise that will resolve to the new node material
|
|
|
+ */
|
|
|
+ public static ParseFromSnippetAsync(snippetId: string, scene: Scene, rootUrl: string = ""): Promise<NodeMaterial> {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ var request = new WebRequest();
|
|
|
+ request.addEventListener("readystatechange", () => {
|
|
|
+ if (request.readyState == 4) {
|
|
|
+ if (request.status == 200) {
|
|
|
+ var snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);
|
|
|
+ let serializationObject = JSON.parse(snippet.nodeMaterial);
|
|
|
+ let nodeMaterial = SerializationHelper.Parse(() => new NodeMaterial(snippetId, scene), serializationObject, scene, rootUrl);
|
|
|
+
|
|
|
+ nodeMaterial.loadFromSerialization(serializationObject);
|
|
|
+ try {
|
|
|
+ nodeMaterial.build(true);
|
|
|
+ resolve(nodeMaterial);
|
|
|
+ } catch (err) {
|
|
|
+ reject(err);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ reject("Unable to load the snippet " + snippetId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ request.open("GET", this.SnippetUrl + "/" + snippetId.replace("#", "/"));
|
|
|
+ request.send();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Creates a new node material set to default basic configuration
|
|
|
* @param name defines the name of the material
|
|
|
* @param scene defines the hosting scene
|