- /
- /
- /
3D Plugins – Molds (Meshes)
See 3D Plugin Template to get started.
Molds (Meshes with Wrappers) JavaScript – These are 3D objects, shapes, particle systems, and Babylon Code produced effects (like smoke) used in the 3D Scenes. Use this to create or add your own custom Molds (Meshes). These Molds and Web Molds can be used in 3D Communities, 3D Buildings, and 3D Things.
JavaScript Functions
There 3 functions to add a mold to the scene:
Mold Creation – This s the Babylon code that creates the Meshes.
Mold Default Values – It sets the initial relative Position, Scaling, Rotation, materials, etc… For example, when we create a Box it starts at Scaling 10 x 10 x 10.
Mold Form Fields – The Mold form handles a lot different ways to edit Meshes. This section sets the div sections to show or hide. For example a landscape needs the section for selecting a HeightMap.
These 3 main functions are shown below.
DEVID_PLUGINTEMPLATE – Your Dev ID and Plugin Name in the same format (Caps and Underscore)
Replace MyCustomMold with your DEVID and the name of the mold.
DEVID_PLUGINTEMPLATE.prototype.addMoldMyCustomMold = function(moldname, molddef, lenx, leny, lenz) {
var mold;
try {
mold = BABYLON.MeshBuilder.CreateBox(moldname, {}, scene);
mold.scaling = new BABYLON.Vector3(lenx,leny,lenz);
mold.material = WTW.addCovering(“hidden”, moldname, molddef, lenx, leny, lenz, “0”, “0”);
mold.material.alpha = 0; /* everything you create in this function should be parented to the above invisible Box: */
/* yourobject.parent = mold;
/* so that your 3D Objects position, scaling, and rotatation work as child objects */
/* if needed you can replace the mold directly with your 3D Object. */
/* examples of existing 3D Objects can be found at /core/scripts/molds/wtw_basicmolds.js */} catch (ex) {
WTW.log(“plugins:devid-plugintemplate:scripts-custom_molds.js-addMoldCustom=” + ex.message);
}
return mold;
}
DEVID_PLUGINTEMPLATE.prototype.setNewMoldDefaults = function(shape, positionX, positionY, positionZ, rotationY) {
try {
/* shape is name of my custom mold all lowercase and no spaces */
switch (shape) {
case “mycustommold”:
/* position x, y, x and rotationy are calculated from the current camera position so it is in front of the camera */
dGet(‘wtw_tmoldpositionx’).value = positionX;
dGet(‘wtw_tmoldpositiony’).value = positionY;
dGet(‘wtw_tmoldpositionz’).value = positionZ;
dGet(‘wtw_tmoldscalingx’).value = “1.00”;
dGet(‘wtw_tmoldscalingy’).value = “1.00”;
dGet(‘wtw_tmoldscalingz’).value = “1.00”;
dGet(‘wtw_tmoldrotationx’).value = “0.00”;
dGet(‘wtw_tmoldrotationy’).value = rotationY;
dGet(‘wtw_tmoldrotationz’).value = “0.00”;
dGet(‘wtw_tmoldspecial2’).value = “0.00”;
dGet(‘wtw_tmolduoffset’).value = “0.00”;
dGet(‘wtw_tmoldvoffset’).value = “0.00”;
dGet(‘wtw_tmolduscale’).value = “0.00”;
dGet(‘wtw_tmoldvscale’).value = “0.00”;
dGet(‘wtw_tmoldsubdivisions’).value = “12”;
break;
}
} catch (ex) {
WTW.log(“plugins:devid-plugintemplate:scripts-custom_molds.js-setNewMoldDefaults=” + ex.message);
}
}
DEVID_PLUGINTEMPLATE.prototype.setMoldFormFields = function(shape) {
try {
/* shape is name of my custom mold all lowercase and no spaces */
switch (shape) {
case “mycustommold”:
/* define the labels and button names used on the form */
dGet(‘wtw_moldpositiontitle’).innerHTML = “MyCustomMold Position”;
dGet(‘wtw_moldscalingtitle’).innerHTML = “MyCustomMold Length”;
dGet(‘wtw_moldrotationtitle’).innerHTML = “MyCustomMold Rotation”;
dGet(‘wtw_moldtexturetitle’).innerHTML = “MyCustomMold Texture Image”;
dGet(‘wtw_moldbumptexturetitle’).innerHTML = “MyCustomMold Bump Image”;
dGet(‘wtw_bsavethismold’).innerHTML = “<u>S</u>ave MyCustomMold”;
dGet(‘wtw_bdelmold’).innerHTML = “<u>D</u>elete MyCustomMold”;
dGet(‘wtw_editmoldformtitle’).innerHTML = “Edit MyCustomMold”;/* show or hide the section divs on the form (/core/forms/mold.php) */
WTW.hide(‘wtw_moldspecial1’);
WTW.hide(‘wtw_moldspecial2’);
WTW.show(‘wtw_moldsubdivisions’);
WTW.show(‘wtw_moldtexturetitle’);
WTW.show(‘wtw_moldtexturepreview’);
WTW.show(‘wtw_moldscalediv’);
WTW.show(‘wtw_moldmergemoldsdiv’);
break;
}
} catch (ex) {
WTW.log(“plugins:devid-plugintemplate:scripts-custom_molds.js-setMoldFormFields=” + ex.message);
}
return mold;
}
Hooks
Hooks are PHP code that will tie the JavaScript functions into the WalkTheWeb code in the correct place for execution.
Hooks are added in the Plugin/functions/class_plugin.php file, initHooks function.
/* $wtwplugins->addMoldDef(mold name, list, function); */
$wtwplugins->addMoldDef(“My Custom Mold”, “webmold”, “devidplugintemplate.addMoldMyCustomMold(moldname, molddef, lenx, leny, lenz);”);/* $wtwplugins->addScriptFunction(hook, function); */
$wtwplugins->addScriptFunction(“setnewmolddefaults”, “devidplugintemplate.setNewMoldDefaults(shape, positionX, positionY, positionZ, rotationY);”);
$wtwplugins->addScriptFunction(“setmoldformfields”, “devidplugintemplate.setMoldFormFields(shape);”);
addMoldDef function:
Mold Name – the name you want to see on the list.
List – “mold” or “webmold” selects which list to add your Custom Mold.
Function – myJavaScriptClass.function(parameters);
Hook – the name of the function where it is inserted all lowercase Example: setnewmolddefaults.
For a complete and current list of available Hooks, functions, and parameters, see /core/functions/class_wtwplugins.php, getScriptFunctions function.
Sample hook code section:
$jsdata .= ” WTWJS.prototype.pluginsSetNewMoldDefaults = function(shape, positionX, positionY, positionZ, rotationY) {“; /* available parameters */
$jsdata .= ” try {“;
$jsdata .= $this->getScriptFunction(‘setnewmolddefaults‘); /* Hook Name */
$jsdata .= ” } catch (ex) {“;
$jsdata .= ” WTW.log(‘class_wtw-pluginsSetNewMoldDefaults=’ + ex.message);”;
$jsdata .= ” }”;
$jsdata .= ” }”;