(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "three"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("three")); } else { var mod = { exports: {} }; factory(mod.exports, global.three); global.Text2D = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, THREE) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.createText = createText; THREE = _interopRequireWildcard(THREE); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function createText(message, height) { var canvas = document.createElement('canvas'); var context = canvas.getContext('2d'); var metrics = null; var textHeight = 100; context.font = 'normal ' + textHeight + 'px Arial'; metrics = context.measureText(message); var textWidth = metrics.width; canvas.width = textWidth; canvas.height = textHeight; context.font = 'normal ' + textHeight + 'px Arial'; context.textAlign = 'center'; context.textBaseline = 'middle'; context.fillStyle = '#ffffff'; context.fillText(message, textWidth / 2, textHeight / 2); var texture = new THREE.Texture(canvas); texture.needsUpdate = true; //var spriteAlignment = new THREE.Vector2(0,0) ; var material = new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide, map: texture, transparent: true }); var geometry = new THREE.PlaneGeometry(height * textWidth / textHeight, height); var plane = new THREE.Mesh(geometry, material); return plane; } });