Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aframe-troika-text

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aframe-troika-text

An A-Frame component to render text using the Troika 3D text renderer

  • 0.3.2
  • npm
  • Socket score

Version published
Weekly downloads
761
increased by7.64%
Maintainers
1
Weekly downloads
 
Created
Source

aframe-troika-text

Version License

This package provides an A-Frame component and primitive for rendering three-dimensional text using Troika's text renderer.

It has similar performance and quality to A-Frame's built-in SDF text component, but brings some additional advantages:

  • It reads font files directly (ttf, otf, woff) and does not require using an external tool to pre-generate SDF textures with the glyphs you think you'll need.

  • It supports ligatures so you can use fonts like Material Icons.

  • Rather than using a fully custom shader, it patches the built-in Three.js material shaders as needed, so you don't lose all the nice standard shader features like lighting and fog.

API

This package registers both a component (<a-entity troika-text="value:Hello" />) and a primitive (<a-troika-text value="Hello"></a-troika-text>). Use whichever is most convenient for you.

I've attempted to keep the API as close as possible to that of A-Frame's default text component and a-text primitive, however some things don't quite map exactly.

Property on componentAttribute on primitiveDescriptionDefault Value
alignalignMulti-line text alignment (left, center, right, justify).left
anchoranchorHorizontal positioning (left, center, right, align).center
baselinebaselineVertical positioning (top, center, bottom).center
clipRectclip-rectFour comma- or space-separated numbers defining a rectangle (minX, minY, maxX, maxY) outside which pixels will be hidden.no clipping
colorcolorText color. This is a shortcut for specifying a custom material.white
depthOffsetdepth-offsetDepth buffer offset to help prevent z-fighting. Negative numbers are closer to camera, positives further.0
fontfontURL to a font file - can be a .ttf, .otf, or .woff (no .woff2)Roboto loaded from Google Fonts
fontSizefont-sizeEm-height at which to render the font, in world units0.2
letterSpacingletter-spacingLetter spacing in meters.0
lineHeightline-heightLine height as a multiple of the fontSize.derived from font metrics
maxWidthmax-widthMaximum width of the text block at which text will start wrapping, in meters.Infinity (no wrapping)
overflowWrapoverflow-wrapControls how text wraps: "normal" to break at whitespace characters, or "break-word" to break within words.normal
valuevalueThe actual content of the text. Line breaks and tabs are supported with \n and \t.''
whiteSpacewhite-spaceHow whitespace should be handled (i.e., normal, nowrap).normal (behaves like pre-wrap)

Note: It does not currently follow how the built-in text component interacts with a geometry component for auto-sizing and anchoring. I think that's a nice feature so it's probably worth adding; in the meantime just use the maxWidth and anchor/baseline attributes to control it manually.

Changing the material

By default the text will render using a MeshBasicMaterial using the color property described in the table above. But you can also change the material to gain more advanced shader features such as physically-based lighting.

If you are using the <a-troika-text> primitive, you can assign it a material component just as you would any other entity.

<a-troika-text
  value="Hello!"
  material="shader: standard; metalness: 0.8;"
></a-troika-text>

If you are using the troika-text="..." component, you must instead give it a troika-text-material="..." attribute to distinguish the text material from the entity's main material. You can pass it anything supported by the built in material component.

<a-entity
  troika-text="value: Hello!"
  troika-text-material="shader: standard; metalness: 0.8;"
></a-entity>

Installation

Browser

Install and use by directly including the browser files:

<head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
  <script src="https://unpkg.com/aframe-troika-text/dist/aframe-troika-text.min.js"></script>
</head>

<body>
  <a-scene>
    <!-- As a component: -->
    <a-entity troika-text="value: Hello world!"></a-entity>
    
    <!-- As a primitive: -->
    <a-troika-text value="Hello world!"></a-troika-text>
  </a-scene>
</body>
npm

Install via npm:

npm install aframe-troika-text

Then require and use.

require('aframe');
require('aframe-troika-text');

FAQs

Package last updated on 04 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc