Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VRMLLoader? #3728

Closed
mcgredonps opened this issue Aug 7, 2013 · 16 comments
Closed

VRMLLoader? #3728

mcgredonps opened this issue Aug 7, 2013 · 16 comments
Labels

Comments

@mcgredonps
Copy link

Is it operational? It's in the distro but I get some errors when trying to use it.

@mrdoob
Copy link
Owner

mrdoob commented Aug 7, 2013

It can load a bunch of files. I think it was VRML 2.0 only though. However, I was told that doing a X3DLoader would be smarter (and then a VRML to X3D on-the-fly converter).

@cecilemuller
Copy link
Contributor

I think the one who told you that meant that X3D would be "smarter" in the sense that X3D is basically all VRML2 nodes + more nodes, the difference being that X3D has three ways to encode the same data while VRML only has one:

  • Classic: same encoding as VRML, by far the easiest to read by humans and usually smaller than XML
  • XML: easiest to parse
  • Binary: smallest filesize but almost nothing supports it

@mrdoob
Copy link
Owner

mrdoob commented Aug 10, 2013

Oh god... sounds like this is more fragmented than I thought... I wonder what would be the best way to pursue this. Or even if I should pursue this...

@cecilemuller
Copy link
Contributor

Don't worry you don't have to implement every features nor every encoding :)

You could stick to the Interchange profile in XML encoding, that's enough for having meshes and materials.

@mrdoob
Copy link
Owner

mrdoob commented Aug 10, 2013

Is that the most common encoding?

@cecilemuller
Copy link
Contributor

Yes, XML is the most common encoding for X3D.

Actually, Interchange has a conformance test suite with XML-encoded models you could use to test: officially you'd need to be a member of the consortium to access it (100$/year if you're not a student), but as long as you don't share it, I think they'd be OK if I send it to you.

@mcgredonps
Copy link
Author

Is there a known-good VRML file to test the loader with? I'm not sure if my problems relate to the VRML or my code.

"Uncaught TypeError: Object [object Object] has no method 'multiplyScalar'
parseNode
parseNode
parseNode
parseV2
THREE.VRMLLoader.parse

@mrdoob
Copy link
Owner

mrdoob commented Aug 12, 2013

Do you mind sharing the file you're trying to load?

@mcgredonps
Copy link
Author

Code to load:

this.vrmlLoader = new THREE.VRMLLoader();
this.vrmlLoader.load("models/mantaMine.wrl", function(result)
{
console.log("Vrml load result");
});

vrml code:

#VRML V2.0 utf8
# X3D-to-VRML-97 XSL translation autogenerated by X3dToVrml97.xslt
# http://www.web3d.org/x3d/content/X3dToVrml97.xslt
# Generated using XSLT processor: SAXON 9.1.0.6 from Saxonica

# [X3D] VRML V3.0 utf8
# PROFILE Immersive
# [X3D] version=3.0
# [X3D] noNamespaceSchemaLocation=http://www.web3d.org/specifications/x3d-3.0.xsd
# [head]

# META "title" "Manta.x3d"
# META "description" "Italian Manta bottom mine, with truncated cone and handling padeyes."
# META "creator" "Frederic Roussille"
# META "created" "8 May 2001"
# META "modified" "26 October 2001"
# META "identifier" "https://savage.nps.edu/Savage/Weapons/UnderwaterMines/Manta.x3d"
# META "photo" "MantaInert.jpg"
# META "photo" "minelocator.jpg"
# META "photo" "Mine1.jpg"
# META "photo" "Mine2.jpg"
# META "photo" "img055.gif"
# META "photo" "http://www.cisatlantic.com/trimix/strike/minelocator.jpg"
# META "photo" "http://www.cisatlantic.com/trimix/strike/Mine1.jpg"
# META "photo" "http://www.cisatlantic.com/trimix/strike/Mine2.jpg"
# META "photo" "http://www.fas.org/man/dod-101/navy/docs/swos/cmd/miw/Sp6-4-1/img055.gif"
# META "generator" "X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit"
# META "license" "../../license.html"

# [Scene] ========== ========== ==========

NavigationInfo { type [ "EXAMINE" "ANY" ] } ###  Default X3D NavigationInfo

Viewpoint {
  description "Manta mine"
  orientation 1 0 0 -0.4
  position 0 1 3
}
Viewpoint {
  description "Manta top view"
  orientation 1 0 0 -1.57
  position 0 2 0
}
Viewpoint {
  description "Manta side view"
  orientation 0 1 0 -1.57
  position -2 0 0
}
# The Manta mine geometry
Group {
  children [
      Transform {
        rotation 1 0 0 1.57
        scale 1.5 1.5 1
        children [
            Shape {
              appearance Appearance {
                material DEF orange Material {
                  diffuseColor 0.6 0.3 0
                }
              }
              geometry Extrusion {
                beginCap FALSE
                creaseAngle 157
                crossSection [ 0.1 0 0.22 -0.01 0.2275 -0.05 0.2675 -0.05 0.49 0.4 0.49 0.47 0.53 0.47 0.53 0.48 0 0.48 0 0.22 0.0675 0.22 0.1 0 ]
                endCap FALSE
                spine [ 0.001 0 0 0.00092 -0.00038 0 0.00071 -0.00071 0 0.00038 -0.00092 0 0 -0.001 0 -0.00038 -0.00092 0 -0.00071 -0.00071 0 -0.00092 -0.00038 0 -0.001 0 0 -0.00092 0.00038 0 -0.00071 0.00071 0 -0.00038 0.00092 0 0 0.001 0 0.00038 0.00092 0 0.00071 0.00071 0 0.00092 0.00038 0 0.001 0 0 ]
              }
            }
        ]
      }
      Transform {
        rotation 0 1 0 0.785
        translation 0.36 -0.4 0.36
        children [
            DEF triangle Shape {
              appearance Appearance {
                material USE orange
              }
              geometry IndexedFaceSet {
                coordIndex [ 0 1 3 -1 0 1 2 -1 0 2 3 -1 1 3 2 -1 ]
                solid FALSE
                coord Coordinate {
                  point [ 0 0 0.0925 0 0.2775 0.122 -0.0925 0.2775 0 0.0925 0.2775 0 ]
                }
              }
            }
        ]
      }
      Transform {
        rotation 0 1 0 -0.785
        translation -0.36 -0.4 0.36
        children [
            USE triangle
        ]
      }
      Transform {
        rotation 0 1 0 2.355
        translation 0.36 -0.4 -0.36
        children [
            USE triangle
        ]
      }
      Transform {
        rotation 0 1 0 -2.355
        translation -0.36 -0.4 -0.36
        children [
            USE triangle
        ]
      }
      Transform {
        translation 0.4 -0.08 0.4
        children [
            DEF ring Group {
              children [
                  Transform {
                    rotation 1 0 0 1.57
                    children [
                        Shape {
                          appearance Appearance {
                            material DEF grey Material {
                              diffuseColor 0.5 0.5 0.5
                              specularColor 1 1 1
                            }
                          }
                          geometry Extrusion {
                            beginCap FALSE
                            convex FALSE
                            creaseAngle 1.57
                            crossSection [ 0 0 0.007 0 0.018 0.025 0.032 0.035 0.04 0.036 0.04 0.04 0 0.04 0 0 ]
                            endCap FALSE
                            spine [ 0.001 0 0 0.00092 -0.00038 0 0.00071 -0.00071 0 0.00038 -0.00092 0 0 -0.001 0 -0.00038 -0.00092 0 -0.00071 -0.00071 0 -0.00092 -0.00038 0 -0.001 0 0 -0.00092 0.00038 0 -0.00071 0.00071 0 -0.00038 0.00092 0 0 0.001 0 0.00038 0.00092 0 0.00071 0.00071 0 0.00092 0.00038 0 0.001 0 0 ]
                          }
                        }
                    ]
                  }
                  Transform {
                    rotation 0 1 0 0.7535
                    translation 0 0.035 0
                    children [
                        Shape {
                          appearance Appearance {
                            material USE grey
                          }
                          geometry Extrusion {
                            beginCap FALSE
                            creaseAngle 1.57
                            crossSection [ 0.01 0 0.0092 -0.0038 0.0071 -0.0071 0.0038 -0.0092 0 -0.01 -0.0038 -0.0092 -0.0071 -0.0071 -0.0092 -0.0038 -0.01 0 -0.0092 0.0038 -0.0071 0.0071 -0.0038 0.0092 0 0.01 0.0038 0.0092 0.0071 0.0071 0.0092 0.0038 0.01 0 ]
                            endCap FALSE
                            spine [ 0.03 0 0 0.0276 -0.0114 0 0.0213 -0.0213 0 0.0114 -0.0276 0 0 -0.03 0 -0.0114 -0.0276 0 -0.0213 -0.0213 0 -0.0276 -0.0114 0 -0.03 0 0 -0.0276 0.0114 0 -0.0213 0.0213 0 -0.0114 0.0276 0 0 0.03 0 0.0114 0.0276 0 0.0213 0.0213 0 0.0276 0.0114 0 0.03 0 0 ]
                          }
                        }
                    ]
                  }
              ]
            }
        ]
      }
      Transform {
        rotation 0 1 0 1.57
        translation -0.4 -0.08 0.4
        children [
            USE ring
        ]
      }
      Transform {
        rotation 0 1 0 1.57
        translation 0.4 -0.08 -0.4
        children [
            USE ring
        ]
      }
      Transform {
        translation -0.4 -0.08 -0.4
        children [
            USE ring
        ]
      }
      Transform {
        translation 0 -0.11 0
        children [
            Shape {
              appearance Appearance {
                material Material {
                  diffuseColor 0.5 0.5 0.5
                  specularColor 0.2 0.2 0.2
                }
              }
              geometry Cylinder {
                height 0.22
                radius 0.15
              }
            }
        ]
      }
      Transform {
        rotation 0 0 1 0.935
        translation -0.461 -0.04 0
        children [
            DEF hole Shape {
              geometry Cylinder {
                height 0.01
                radius 0.04
              }
              appearance Appearance {
                material Material {
                  diffuseColor 0 0 0
                }
              }
            }
        ]
      }
      Transform {
        rotation 0 0 1 -0.935
        translation 0.461 -0.04 0
        children [
            USE hole
        ]
      }
      Transform {
        rotation 1 0 0 -0.935
        translation 0 -0.04 -0.461
        children [
            USE hole
        ]
      }
      Transform {
        rotation 1 0 0 0.935
        translation 0 -0.04 0.461
        children [
            USE hole
        ]
      }
  ]
}

@cecilemuller
Copy link
Contributor

It seems to arise when the parser encounters a Transform.rotation. For example, this tiny model also triggers the same error:

#VRML V2.0 utf8
Transform {
    rotation 0 1 0 0.4
    children Shape {
        appearance Appearance {
            material Material {}
        }
        geometry Box {}
    }
}

By the way @mcgredonps, something unrelated about that model: the main mesh has its normals flipped (so you see the inside when you should see the outside the shape), so you may want to add ccw FALSE in the first Extrusion node.

@cecilemuller
Copy link
Contributor

The error comes from line 160 because THREE.Euler has no method multiplyScalar:

object.rotation.set(
    parseFloat( result[ 1 ] ),
    parseFloat( result[ 2 ] ),
    parseFloat( result[ 3 ] )
).multiplyScalar( result[ 4 ] );

So I think it could be replaced with this:

object.quaternion.set(
    parseFloat( result[ 1 ] ),
    parseFloat( result[ 2 ] ),
    parseFloat( result[ 3 ] ),
    parseFloat( result[ 4 ] )
);

@mrdoob
Copy link
Owner

mrdoob commented Aug 13, 2013

Uhm... So VRML rotation is a quaternion? I don't remember how I came up with that object.rotation.set().multiplyScalar() code...

@cecilemuller
Copy link
Contributor

Yes, SFRotation values (like Transform.rotation) are quaternions :)

By the way, do you still have somewhere a working example of the loader loading a scene (even if it uses an older version of the renderer) ? Just wanted to check I didn't mess things up before even attempting a pull request.

@mcgredonps
Copy link
Author

Thanks, I just grabbed some random student model off our archive. https://savage.nps.edu has a lot of x3d/vrml models.

mrdoob added a commit that referenced this issue Aug 14, 2013
@Patel2014
Copy link

Could you please give me the link of example which loads vrm object?

Thanks

@cecilemuller
Copy link
Contributor

@mrdoob mrdoob closed this as completed Apr 2, 2014
ma-tech pushed a commit to ma-tech/MARender that referenced this issue Mar 17, 2017
Updated VRMLLoader to use object.quaternion instead of object.rotation
as mentioned in issue mrdoob/three.js#3728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants