enter image description here
enter image description here
I am having issues adding the three.js libraries. Can anyone help me?
According to your error message, you are missing to define an import map in your index.html. Do it like so:
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims#1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "./three/build/three.module.js"
}
}
</script>
You can then change the THREE import to:
import * as THREE from 'three';
The error is actually produced in your example files since OrbitControls and GLTFLoader use the bare import specifier three. So without an import map, the browser can't resolve the specifier.
I had the same problem and this worked for me. It uses CDNs, but at least it works (also for firebox):
<script async src="https://unpkg.com/es-module-shims#1.6.0/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://cdn.skypack.dev/three#0.144.0/build/three.module",
"three/": "https://cdn.skypack.dev/three#0.144.0/"
}
}
</script>
<script src="szene2.js" type="module"> </script>
In your javascript:
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader';
Related
So I find a lot of interesting scripts that are built just with threejs, but I would like to somehow combine them with the ease of use that Aframe provides.
The below code starts by importing three.module.js - which I believe is already bundled with Aframe, so how can I include/import the required files and use them within a component?
I have had some joy including the three.module.js in my files and loading it exactly as below, but this seems like an unnecessary requirement/duplication of code.
<script type="module">
import * as THREE from '../build/three.module.js';
import { GUI } from './jsm/libs/dat.gui.module.js';
import { EffectComposer } from './jsm/postprocessing/EffectComposer.js';
import { RenderPass } from './jsm/postprocessing/RenderPass.js';
import { AfterimagePass } from './jsm/postprocessing/AfterimagePass.js';
EDIT:
Think I may be slowly getting there
<script src="./scripts/Pass.js"></script>
<script src="./scripts/CopyShader.js"></script>
<script src="./scripts/ShaderPass.js"></script>
<script src="./scripts/EffectComposer.js"></script>
<script src="./scripts/RenderPass.js"></script>
<script src="./scripts/AfterImageShader.js"></script>
<script src="./scripts/AfterImagePass.js"></script>
<script>
let composer;
let mesh;
let afterimagePass;
document.querySelector('a-scene').addEventListener('loaded', function () {
console.log(sceneEl.renderer.getSize());
composer = new THREE.EffectComposer( sceneEl.renderer );
composer.addPass( new THREE.RenderPass( sceneEl, sceneEl.camera ) );
afterimagePass = new THREE.AfterimagePass();
composer.addPass( afterimagePass );
composer.render(sceneEl, sceneEl.camera);
});
</script>
But now it's throwing this error
three.js:19204 Uncaught TypeError: t.onBeforeRender is not a function
at qe.render (three.js:19204)
at RenderPass.render (RenderPass.js:52)
at EffectComposer.render (EffectComposer.js:123)
at HTMLElement.<anonymous> ((index):982)
at HTMLElement.<anonymous> (a-node.js:263)
at a-node.js:128
Three.js doesn't currently support post processing for VR (https://github.com/mrdoob/three.js/pull/15840). While you might be able to get post processing to work in A-Frame using the default 2D camera, it currently breaks as soon as you switch to VR or AR -- this is due to the Three.js dependency, not A-Frame itself. To get 2D post processing to work in A-Frame you might try binding the EffectComposer to the A-Frame render loop (https://gist.github.com/donmccurdy/31560945d5723737e6c656a2974ab628).
Not usually a JS programmer. I setup a new WebStorm project, used npm to install three.js, everything looks fine, but when I try to import it the import statement is fine, but you can't use it, nothing is code completed.
Clearly I am missing something important. Three appears correctly in the package.json and lock json and I have all the files in the usual node_modules. Any use of the import THREE shows nothing. There are no errors, just warnings about the unused items and WebGLRenderer is undefined.
This is the default WebStorm setup with ECMAScript 6.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script type="module">
import * as THREE from 'three';
function main()
{
const canvas = document.querySelector('#c');
const renderer = new THREE.WebGLRenderer({canvas});
}
</script>
<canvas id="c"></canvas>
</body>
</html>
Restarting Webstorm made it work again. The app was running for a couple weeks, so perhaps there is memory leak or other issue.
I am in Browser trying to initialize Vuetify and I believe this used to work but now fails...
//In Node
app.use(serve("./node_modules/vuetify/dist"));
// On Client
<script type="module">
import * as Vuetify from '/vuetify/vuetify.js';
const global = window || global;
global.Vuetify = Vuetify;
Vue.use(Vuetify, {
...
});
</script>
When I run I get
Error in beforeCreate hook: "Error: Vuetify is not properly initialized, see https://vuetifyjs.com/getting-started/quick-start#bootstrapping-the-vuetify-object"
I tried changing to...
//In Node
app.use(serve("./node_modules/vuetify"));
// On Client
<script type="module">
import Vuetify from "/vuetify/lib";
const global = window || global;
global.Vuetify = Vuetify;
Vue.use(Vuetify, {
...
});
</script>
But it still fails this time with
GET https://localhost:3001/vuetify/lib net::ERR_ABORTED 404
I even tried changing to...
//In Node
app.use(serve("./node_modules/vuetify"));
// On Client
<script type="module">
import Vuetify from "/vuetify/lib/index.js";
const global = window || global;
global.Vuetify = Vuetify;
Vue.use(Vuetify, {
...
});
</script>
Then I get...
GET https://localhost:3001/vuetify/lib/components net::ERR_ABORTED 404
I think the js files are not proper ES6 definitions (IE no extensions mjs, cjs) but is there a way to get it to work?
For additional context this is how I load Vue
import Vue from '/vue/vue.esm.browser.js'
const global = window || global;
global.Vue = Vue;
This works fine
you could try importing the script in a script tag: https://cdnjs.com/libraries/vuetify
I think the link you want is this: https://cdnjs.cloudflare.com/ajax/libs/vuetify/2.0.17/vuetify.js
I would like to make a page with vue.js and laravel, where I can show a pdf in a vue-component. I found a great lib for that vue-pdf, what can show the PDFs.
My problem is that the PDF reader can not zoom (in/out), is there any solution for that, (e.g.: css / js hack) or can anybody recommend me an another pdf reader in vue system?
Thanks in advance!
You might want to take a look at npm's panzoom
<template>
<pdf #loaded="onLoad" src="yourpdf.pdf" page="1" ref="mypdf"></pdf>
</template>
<script>
import pdf from 'vue-pdf';
import panzoom from 'panzoom';
export default {
components: {
pdf
},
methods: {
onLoad() {
panzooom(this.$refs.mypdf);
}
}
}
</script>
I am evaluating angular 2.0 beta (with typescript) and tried to include some libraries via the module system. But somehow this does not work for c3.js / nv.d3.js.
Can anyone bump me into the right direction on how to c3.js / nv.d3.js to work?
tsconfig.json has "module": "system" (recommended by Angular 2.0)
tsconfig.json has "allowSyntheticDefaultImports": true (allows synthetic default import of d3.js)
import d3 from 'd3' works
import c3 from 'c3' does not work
import nv from 'nvd3' does not work
The c3.js site says import via AMD and require.js is possible.
The system.js site says it can import AMD modules as well
I am no JS pro, but there is no export statement in c3.js / nv.d3.js file, also there is no typescript definition in tsd. I'd create one and share it, but am not familiar enough with the concepts needed.
Seems I have to wait for the library developers to add a .d.ts declaration or add an export. Possible solutions for the meantime seem to be:
this:
Load "Vanilla" Javascript Libraries into Node.js
or: just declare c3 / nv and assume it's there at runtime
add to index.html: <script src="libs/c3.js"></script>
and in typescript: declare var c3;
add to index.html: <script src="libs/nv.d3.js"></script>
and in typescript: declare var nv;
I'm using Angular2 2.0.0-beta.17 and in a similar situation, building a proof of concept app with graphs and charts.
First, I imported the libraries using npm.
Next, these libraries are untyped Javascript but we can do something about that. if you are using Typings (and I recommend it) you can add these definitions to your typings.json (mine are under ambient):
"d3": "github:DefinitelyTyped/DefinitelyTyped/d3/d3.d.ts",
"nvd3": "github:DefinitelyTyped/DefinitelyTyped/nvd3/nvd3.d.ts",
"c3": "github:DefinitelyTyped/DefinitelyTyped/c3/c3.d.ts
I also had trouble importing. So, as a workaround I declared them:
declare var d3, nv: any;
Also, have a look at Krispo's ng2-nvd3 project which supplies an nvd3 component for Angular2
This project only worked for after I made the declarations changes.
I hope this helps -- I'm learning Angular2 myself so if anyone has some best practices, please share. The "declare... any" workaround does not seem optimal.
Thanks,
Cody
Assuming you are installing nvd3 as an npm package.
In the file where you bootstrap your app module do :
import 'nvd3/build/nv.d3';
import {enableProdMode} from '#angular/core';
import {platformBrowserDynamic} from '#angular/platform-browser-dynamic';
import {AppModule} from './app';
declare var process: any;
if (process.env.NODE_ENV === 'production') {
enableProdMode();
} else {
}
platformBrowserDynamic().bootstrapModule(AppModule);
And in the component .ts file do :
declare var nv:any;
This is how I implemented c3 chart in Ionic 2 -- similar to what Rob mentioned earlier :
Include the following links to index.html
<link rel="stylesheet" type="text/css" href="assets/js/c3.min.css">
<script type="text/javascript" src="assets/js/d3.min.js"></script>
<script type="text/javascript" src="assets/js/c3.min.js"></script>
Below is the implementation in the .ts file:
import {Component} from '#angular/core';
declare var c3;
declare var d3;
#Component({
templateUrl: 'graph.html'
})
export class GraphC3 {
constructor() {
}
ngOnInit() {
let chartoutput = c3.generate({
bindto: '#chart',
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
]
}
});
}
}
In your graph.html file includes
<div id="chart"></div>