You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The following rules and limitations also apply to components: </p>
3201
+
<ul>
3202
+
<li>The <code>names</code> and types of configurable value elements must always match</li>
3203
+
<li>The tag <code>name</code> given for the component must include a hyphen '-'</li>
3204
+
<li>The component tag itself (eg. <code><x-cube></code>) acts as a <ahref="#the-group-element">group element</a> in the scene</li>
3205
+
<li>Nested templates are not supported, but a template may contain other web components</li>
3206
+
<li>Each child node of a web component can only be inserted into a single <code><content></code> slot (described below). Children without a matching content slot are ignored.</li>
3207
+
</ul>
3208
+
3209
+
<section>
3210
+
<h3>Registration</h3>
3211
+
<p>Web components must be registered with the browser before they can be used. XML3D provides a convenience interface for this and it is recommended
3212
+
that you use this to register your web components rather than registering them manually. The simplest way to register a web component is to
3213
+
pass a URL string to an HTML file containing the <code>template</code> element:</p>
3214
+
3215
+
<preclass="example highlight">
3216
+
var promise = XML3D.registerComponent("path/to/component/template.html");
3217
+
</pre>
3218
+
3219
+
<p>The registration function will return a Promise object that resolves when the component template has been registered with the browser. At that
3220
+
point you may begin creating instances of the component. The Promise will reject if the component template could not be found or if an error was
3221
+
encountered during the registration process.</p>
3222
+
3223
+
<p>Optionally you can include your own prototype object for a web component. This allows you to hook into the standard lifecycle callbacks of the
3224
+
web component (eg. <code>createdCallback</code>) and to define custom functions that will be available on your web component. The example below registers
3225
+
a component that provides the function <code>myFunction</code> on the web component's DOM element:</p>
<p>For more information about the various lifecycle callbacks see the <ahref="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements">
3240
+
Custom Elements
3241
+
</a> documentation. Note that XML3D's own lifecycle callbacks will always be called first even when providing your own. These internal callbacks will
3242
+
take care of things like creating a shadow root and filling it with the component's template.</p>
3243
+
3244
+
</section>
3245
+
3246
+
<section>
3247
+
<h3>Configuration</h3>
3248
+
3249
+
<p>XML3D supports using content elements and attributes to configure web components.
3250
+
The following example uses a content element to configure the color of the cube and an attribute to configure its opacity:</p>
<x-cube opacity="0.5"> <!-- Set the cube's opacity to 0.5 -->
3266
+
<float3 name="diffuseColor">1 0 1</float3> <!-- This float3 will be appended to the above content slot, overriding the default float3 -->
3267
+
</x-cube>
3268
+
</group>
3269
+
</xml3d>
3270
+
</pre>
3271
+
3272
+
<p>Content elements can also be used to add renderable objects or even other web components, however in this case they will <em>not</em> override
3273
+
existing defaults, but will instead be rendered alongside them:</p>
0 commit comments