Giter VIP home page Giter VIP logo

Comments (10)

create3000 avatar create3000 commented on July 3, 2024

Prototype can only be created using declarative syntax, they are not made to be created per scripting. You would create a function which returns one or more nodes, which is almost what a prototype does.

from x_ite.

Wagyx avatar Wagyx commented on July 3, 2024

Okay, what about InstancedShape ? I would like to display thousands of spheres and cylinders in the scene with a specific transform for each. For now, I am creating thousands of shapes making the browser slow to load and decreasing the framerate.
What if I use fromXmlString to load a node ?
I could also create the geometry for one sphere myself and duplicate and merge them into a large TriangleSet.
I'll be trying these solutions today, will report back on what works. If you have other ideas about what might work, please let me know.

from x_ite.

create3000 avatar create3000 commented on July 3, 2024

InstancedShape is made for this task. Of course you can use Browser.createX3DFromString to load a data with a protoype.

const scene = await browser .createX3DFromString (`PROTO Foo [
# fields come here
]
{
# Body comes here
}`);

// Now create an instance:
const instance = scene .createProto ("Foo");

from x_ite.

Wagyx avatar Wagyx commented on July 3, 2024

Okay, I have tried the InstancedShape in a simple X3D scene. No JS is involved.
I noticed that you need to add a header with a X_ITE component before the Scene tag like so:

<head>
    <component name='X_ITE' level='1'/>
</head>

Otherwise I get the following error in the Chrome browser and the Shape does not display

XML Parser: Unknown node type 'InstancedShape', you probably have insufficient component/profile statements and/or an inappropriate specification version.

I am just putting this here in case it helps other people.
I guess the InstancedShape is not standard X3D and I missed the place in the doc where this component stuff was indicated.

from x_ite.

Wagyx avatar Wagyx commented on July 3, 2024

Found it in the InstancedShape description ...
Just need to find how to tell the browser to use this component with JS now.

from x_ite.

Wagyx avatar Wagyx commented on July 3, 2024

This works for modifying the header

    const comp = xBrowser.getComponent ("X_ITE", 1);
    scene.addComponent(comp);

But I still get Unknown node type 'InstancedShape' when creating the node const instShape = scene.createNode("InstancedShape");

from x_ite.

create3000 avatar create3000 commented on July 3, 2024
const scene = await browser .createX3DFromString (`

COMPONENT X_ITE : 1

PROTO Foo [
# fields come here
]
{
# Body comes here
}`);

// Now create an instance:
const instance = scene .createProto ("Foo");

Add a component statement like the above.

from x_ite.

create3000 avatar create3000 commented on July 3, 2024

If you do it in the parser, you must first load the components:

scene .addComponent (browser .getComponent (componentName));

this .loadComponents () .then (() =>
{
     this .resolve (scene);
})
.catch (this .reject);

Where loadComponents is defined in X3DParser.

from x_ite.

Wagyx avatar Wagyx commented on July 3, 2024

Thank you very much, that did the trick !
Is there a way to change the color of each instance ? Defining a color array in the material perhaps ? or having a colors property in the instancedShape like the rotations would be pretty neat.

from x_ite.

create3000 avatar create3000 commented on July 3, 2024

No this is not possible. If you have only a few colors, you could create a InstancedShape node for every color, otherwise you can create one big geometry with all faces and colors.

from x_ite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.