Exploring the possibilities with Polymer and three.js

I've been attempting to integrate a three.js demo from http://jsfiddle.net/hfj7gm6t/ into my polymer app, but I'm encountering an error message:

com-model-viewer.html:33 Uncaught TypeError: Cannot read property 'myview' of undefined

<link rel='import' href='../../../bower_components/polymer/polymer.html'>
<dom-module id='com-model-viewer'>
<template>
<ul id='myview'>
</ul>
</template>
<script>
Polymer({
is:'com-model-viewer',
ready: function(){
  console.log(this);
  var camera, scene, renderer;
  var geometry, material, mesh;

  init();
  animate();

  function init(){

    console.log();
    camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.z = 1000;
    scene = new THREE.Scene();
    geometry = new THREE.BoxGeometry(200, 200, 200);
    material = new THREE.MeshBasicMaterial({
      color: 0xff0000,
      wireframe: true
    });
    mesh = new THREE.Mesh(geometry, material);
    scene.add(mesh);
    renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    Polymer.dom( this.$.myview ).appendChild(node);
  }

  function animate(){
    requestAnimationFrame(animate);
    mesh.rotation.x += 0.01;
    mesh.rotation.y += 0.02;
    renderer.render(scene, camera);
  }
}
});
</script>
<script src='../../../node_modules/three/three.min.js'></script>
</dom-module>

Answer №1

It appears that the reference to this within your function init may not be what you intended. The use of this typically points to the function itself rather than the polymer object. Consider passing the original this variable into the init function or alternatively, consider rewriting init as an ES6 arrow function.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to incorporate a translate, rotate, and scale tool into my threejs environment?

Recently, I experimented with the THREE.js editor tool. When you click on an object, a set of tools for translation, rotation, and scaling appear in the scene. These tools allow you to modify the object's position, rotation, and size. I attempted to u ...

Changing an ng-repeat filter following the manual update of a text input

Utilizing jQuery auto-complete to automatically populate values as users type into a text input. <input type="text" ng-model="tags" name="tags" id="tags" value="" /> Subsequently, the ng-repeat is filtering content based on the entered text <di ...

What are some effective strategies for keeping content from shrinking in a drawer menu?

I am currently using a tutorial from https://www.w3schools.com/howto/howto_js_sidenav.asp to create a drawer sidebar menu. However, in my scenario, I need to include a wall of text instead of <a> links. The issue I am facing is that the text expands ...

Obtain the GMT date for the next day

Need help with code to get the current date and the current date + 1 day (in GMT). var now = new Date(); var newexp = (now + 3); var show = newexp.getGMTString(); alert(show); Goal is to set a cookie to expire in 1 day. function SetCookie(name, value, ...

Issue with Material-UI tab when using a datatable within it's content

I implemented the Simple Tabs feature from Material-UI with a Tab containing a Datatable using React-Data_Table. However, I noticed that this particular tab is not responsive like the others when the table is full. Empty Full Here's a snippet of th ...

Arrange the items that are missing from Array B to be located at the bottom of Array A, organized in a file tree structure

I have two arrays containing different types of objects. Each object in the arrays has a title assigned to it. My goal is to compare these two arrays based on their titles and move any files that are not included in the bottom part of the fileStructure arr ...

Type of element returned

Is there a way to retrieve the element type? I'm interested in applying the style of a class to HTML5 elements without using the class attribute. <!DOCTYPE> <html> <head> <title>My page</title> </head& ...

What is the reason for not storing information from MySQL?

Looking to extract data from a website using this JavaScript code. var i = 0 var oldValue = -1 var interval = setInterval(get, 3000); function get(){ var x= $($('.table-body')[1]).find('.h-col-1') if(i!=5){ if(oldValue != x){ old ...

Multiple onClick events being triggered unexpectedly upon component re-render

My react component is a form that triggers a function to handle data saving and other tasks when the send/submit button is clicked. The issue arises when the component seems to re-render multiple times after the button click, most likely due to updated ex ...

Executing functions in a loop using Angular

Within my component, there is a foreach loop triggered when a client is selected. Inside this loop, I need to execute a function within the same component. The issue arises with calling the function using `this.functionName()` because 'this' no ...

Utilizing Vuex state within Vue-Router route definitions

My Vuex store setup in main.js looks like this: import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) //initialize the store const store = new Vuex.Store({ state: { globalError: '', user: { ...

Endless jasmine timeout

This question is a continuation of a discussion on the Remove timeout for single jasmine spec GitHub issue. Query: Can a single test be configured to never time out? The Issue: While it's possible to set a global timeout value using DEFAULT_TIMEOU ...

How can one restrict the display of fields in the Meteor aldeed tabular package?

How can I restrict certain data from being displayed in an aldeed tabular datatable? For instance, if my collection includes attributes A, B, C, D and attribute C contains sensitive information that should not be published, is there a way to prevent it fro ...

'Error: Points is not a valid function' encountered in Node.js

While attempting to run the code below in Node.js, I encountered the following error. The code consists of three files: the dao file which connects to a MongoDB database, the server file, and the index1 file. var mongoose = require('mongoose'); ...

What steps can be taken to resolve the connectivity issue between Heroku and Mongodb?

I seem to be having trouble connecting mongodb and heroku. Surprisingly, I encounter no issues with the connection locally. Click here for Heroku logs --tail Even after trying a database URI that worked without problems on heroku, it still doesn't ...

Feature exclusively displays malfunctioning image URLs for the web browser

Hello everyone! I've been diving into learning JavaScript and recently attempted to create a function that randomly selects an image from an array and displays it on the browser. Unfortunately, despite my efforts, all I see are broken link images. Her ...

Exploring creative art with Three.js streaming

I'm seeking advice on the best way to handle a large amount of data from a stream in Three.js, without needing to store it in memory for the entire application's lifespan. In traditional WebGL, this is typically achieved with gl_drawArray. Howev ...

Shifting hues of colors on website based on geographical location

Working on a new project, I encountered an issue with two elements sharing the same class but displaying different color shades. Has anyone experienced this before and knows what could be causing it? UPDATE Here is an excerpt of the code: The Class: .su ...

How can I trigger a function after all nested subscriptions are completed in typescript/rxjs?

So I need to create a new user and then create two different entities upon success. The process looks like this. this.userRepository.saveAsNew(user).subscribe((user: User) => { user.addEntity1(Entity1).subscribe((entity1: EntityClass) => {}, ...

Ways to stop the transmission of the Origin HTTP header in the Chrome browser?

Scenario: I am managing a production web server, such as https://example.com, which is configured with CORS restrictions that do not allow localhost origins. Developers working on localhost are creating a new page/module that requires making AJAX calls t ...