GrimoireGL / GrimoireJS

A WebGL framework for Web development.
https://grimoire.gl
MIT License
350 stars 24 forks source link

Needs some methods to define node for templating node structure feature #435

Open kyasbal opened 7 years ago

kyasbal commented 7 years ago

Sometimes, we needs to define some node structure like Prefab in unity

kyasbal commented 7 years ago

Basically, current node system is like Prefab non containing children. It means node system is already has such feature. If the node can be defined with children, it seems Prefab basically.

So, this is suggestion of feature.

gr.registerNode("aaa",[COMPONENTS...],{ default values...},[ child structure],"base-node-name");

For consistency, 4th argument should be able to receive string as base node name also. The most important thing in this suggestion is child structure part.

This shall contain some nodes like below.

["bbb","ccc","ddd"]

The declared node aaa should have 3 nodes(bbb,ccc and ddd) as children by default.

`[["bbb",{default values}],"ccc"]

The declared node aaa should have 2 nodes(bbb and ccc) as children by default. And the node bbb have default values to override default value of node bbb.

Therefore, order of priority should be rewritten as below.

User specified value > (Prefab specified value) > default value on node > Default value on component

moajo commented 7 years ago

I think this notation will break the consistency of node system. When using such nodes in GOML, how do you notate their child nodes? I think that the notation of GOML does not match the structure of the tree. Furthermore, it seems that it is not possible to modify attributes of defined child nodes from GOML.

I think that this function should be implemented on the existing node and component framework.

so, I propose template node and Template component instead.

template node

Definition

gr.registerNode("template",[TemplateComponent]);

Usage

<template goml="template.goml" autoResolve="true"/>

Template Component replace this node by template.goml. if autoResolve is true, resolve template automaticaly when on awake or mount or any other timing.

Template Component

var tmp = gr("*")("template").first().getComponent("Template");

// template from GOML
tmp.setAttribute("goml",goml_data);

// clone other node tree structure.
tmp.clone(gr("*")("#template_target").firsst());

//execute parsing template and replace this node manually.
tmp.resolve();
kyasbal commented 7 years ago

その他の属性はルートに付与