question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typecast fails if `getObjectByName` method returns objects other than Object3D

See original GitHub issue

Please refer the example mentioned below:

const scene = new THREE.scene()
const upperPlaneCloudMaterial = new THREE.PointsMaterial({
            vertexColors: THREE.VertexColors,
            size: 0.08,
            clippingPlanes: []
        })
const pointsObject = new THREE.Points(this.cloudGeometry, upperPlaneCloudMaterial)
const pointsObject.name = 'pointsObject'
scene.add(this.cloudField)

Now while getting cloud field by method getObjectByName()

const pointsObject = scene.getObjectByName('pointsObject')
pointsObject.geometry.attributes.position.needsUpdate = true
pointsObject.geometry.attributes.position.setArray(attributesData.position)
pointsObject.geometry.computeBoundingSphere()

It gives type error as mentioned below: Property 'geometry' does not exist on type 'Object3D'

Three.js version
  • Dev
  • r115
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
donmccurdycommented, Apr 16, 2020

I don’t see a cast in your code above — does this also fail to compile in TypeScript?

const points = scene.getObjectByName('pointsObject') as THREE.Points;
const position = points.geometry.getAttribute('position');
1reaction
sarthak-saxenacommented, Apr 17, 2020

@sarthak-saxena It seems @donmccurdy solutions is more appropriate than changing the declaration of getObjectByName(). Can this issue be closed?

Yes we can close this issue now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object3D#getObjectByName – three.js docs
Object gets rendered if true . Default is true . Static Properties. Static properties and methods are defined per class rather than per...
Read more >
Three JS. "Property 'material' does not exist on type 'Object3D ...
I think the problem is that the return type of getObjectByName() is Object3D . And objects of this type do not have a...
Read more >
JavaScript type casting gone wrong | by Glad Chinda
When casting JavaScript values to strings, especially objects, ... The createSalaryObject() function returns a custom JavaScript object that ...
Read more >
Object Type Casting in Java - Baeldung
An overview of type casting in Java, covered with simple and easy to ... There's another way to cast objects using the methods...
Read more >
Casting and runtime type checking (using instanceof)
When the return value of a method is an interface type, the method ... the same method can work with many different underlying...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found