Lumière: a Novel Framework for Rendering 3D Graphics in Smalltalk
Total Page:16
File Type:pdf, Size:1020Kb
Lumière: a Novel Framework for Rendering 3D graphics in Smalltalk Fernando Olivero, Michele Lanza, Romain Robbes REVEAL@ Faculty of Informatics - University of Lugano, Switzerland {fernando.olivero, michele.lanza, romain.robbes}@usi.ch ABSTRACT Squeak, and has thus long left the status of being a frame- To render 3D graphics there is a number of different frame- work that is easy to get into. Jun is less complex than Cro- works written in Smalltalk. While most of them provide quet, but is affected by the licensing policy of VisualWorks, powerful facilities, many of them are outdated, abandoned, despite the fact that Jun itself is free and open. undocumented or heavyweight. Indeed, the Smalltalk community is missing a lightweight and open source 3D framework. To fulfill this need, using In this paper we present Lumi`ere, a novel lightweight 2 framework for rendering 3D graphics using OpenGL based Pharo , we are developing a novel framework for rendering on a stage metaphor. Lumi`ereis implemented using the 3D graphics in Smalltalk called Lumi`ere . Pharo IDE. In its current state it supports basic and com- One of the cornerstones of Lumi`ereis to hinge on the posite shapes to populate 3D scenes, features a camera, and metaphor of a stage. We believe this helps to make the a lighting model. framework and its usage more intuitive, as metaphors are We illustrate the usage of Lumi`erewith Gaucho, an envi- powerful tools to assist the usage of abstract concepts: If ronment for visual programming we are currently building. a framework is built around an intuitive metaphor which maps abstracts concepts to real-world objects, programmers can obtain an immediate mental model of the framework's Categories and Subject Descriptors domain model, thus easing the understanding and usage of D.2.6 [Programming Environments]: Graphical environ- the framework. ments To apply this concept to 3D graphics, Lumi`ere's stage metaphor implies that all graphics are produced by cameras taking pictures of 3D shapes lit by the lights of the stage. A Keywords stage provides the setting for taking pictures of a composi- 3D, Smalltalk, OpenGL tion of visual objects we call micro-worlds. With Lumi`ere a Pharo programmer can produce 3D graphics using high level abstractions (cameras, lights, stages and shapes) instead of 1. INTRODUCTION low-level graphic instructions. Over the years, the Smalltalk language and its many di- We want Lumi`ereto be fully integrated in the Pharo en- alects have featured many frameworks for rendering graph- vironment to provide a seamless user experience. Thus Lu- ics in 3D. Well-known examples include Alice[5] and Cro- mi`ere's rendered stages are integrated with the windows and quet[7] for Squeak, ST3D for Dolphin Smalltalk, and the browsers of the Pharo environment, and makes interactions Jun1 framework for VisualWorks. with a stage possible through the use of the mouse and the However many of the existing frameworks are affected by keyboard. problems such obselence, complexity, and licensing. Squeak In this paper we describe Lumi`ere, the reasons that led Alice is no longer maintained and therefore lacks support to its implementation, the metaphor behind it, its key char- for features present in most modern renderers (for example acteristics and capabilities. To illustrate its usage and po- multi-texturing, Vertex buffer objects, vertex shaders, etc.). tential we describe Gaucho, a 3D environment for visual Croquet, while it is still maintained, has become a complex programming we are currently building. full-fledged collaborative environment that runs on top of Structure of the paper. 1http://www.cc.kyoto-su.ac.jp/~atsushi/Jun/ In Section 2 we describe existing 3D frameworks developed in Smalltalk. In Section 3 we explain the motivation for de- veloping Lumi`ereinstead of using an existing framework. In Section 4 we detail the design and the implementation of Permission to make digital or hard copies of all or part of this work for this novel framework, while in Section 5 we demonstrate the personal or classroom use is granted without fee provided that copies are extensibility of Lumi`ereand in Section 6 we briefly discuss not made or distributed for profit or commercial advantage and that copies the performance of Lumi`ere.Section 7 describes our 3D vi- bear this notice and the full citation on the first page. To copy otherwise, to sual programming environment named Gaucho, built on top republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. of Lumi`ere. Finally, in Section 8 we conclude this paper. IWST’09 August 31, 2009, Brest, France. 2 Copyright 2009 ACM 978-1-60558-899-5 ...$10.00. http://www.pharo-project.org/home 2. RELATED WORK i.e.., whether it is easily loadable (in the best case with Smalltalk has several frameworks and tools for producing just one click) into a Smalltalk image. 3D graphics; these have distinct approaches to the problem • Free commercial usage: this property describes if the of rendering graphics. In this section we categorize the ex- framework can be used in a commercial context with- isting frameworks and compare them according to relevant out any license problems. In Smalltalk this is far from properties. being an irrelevant issue, since deployed applications The frameworks or tools for producing 3D graphics in are inseparable from the virtual machine and the im- Smalltalk can be categorized into two groups, grouped by age containing the language library. the level of abstraction they provide over graphics instruc- tions. The first group contains low level library interfaces • Finally, the framework status is considered, whether it solely providing communication with a 3D library written in is still being maintained or has become obsolete. another language, while the higher level frameworks abstract over the graphic libraries in order to ease graphic program- ming. Balloon3D. This is a renderer for Squeak written entirely in Smalltalk. 2.1 Low level library interfaces It provides lighting, shading, texturing, meshes and ma- Several Smalltalk dialects have interfaces to hardware ac- trix transformations in an object oriented framework. Bal- celerated libraries such as OpenGL and DirectX. loon3D does not provide animations, only rendering a single Examples are the OpenGL interfaces provided by Smalltalk frame at a time. The framework is not maintained anymore X3 and Squeak4 (see Figure 1, B), and Smalltalk MT5 (which and has become outdated, thus it lacks several modern fea- also features a DirectX interface). tures (such as pixel and vertex shaders; multi texturing, While these interfaces allow the programmers to produce etc.). 3D graphics in Smalltalk, they only provide glue code for We considered maintaining and enhancing Balloon3D in- calling graphics primitives. Programmers are forced to think stead of building Lumi`ere,but found several problems with in terms of primitive elements such as vertices, normals and this approach. For example Balloon3D was designed as ren- polygons. Worse, data structures are underused. For in- derer written entirely in Smalltalk, and the hardware accel- stance, the primitives to use a vertex has three floating eration using OpenGL was added later, so we preferred to point parameters instead of a dedicated vertex data struc- build a renderer designed from scratch to take full advantage ture. The data structure used for more complex shapes is of the performance and scalability of OpenGL. Moreover the a simple array of floating-point values. This violates the lack of documentation, usage and maintenance of Balloon3D basic principles of object-oriented programming and forces made us discard the idea of maintaing and enhancing it. developers to deal with painstaking low-level details. The decision to have a low level interface is a sound deci- Squeak Alice. sion for efficiency purposes, in order to render large numbers It is an implementation of Alice[2] for Squeak. It is basi- of polygons. However, abstractions are needed for modeling cally a scene graph based renderer. A scene graph is a hi- purposes, which these libraries do not provide. It is up to erarchical structure for modeling the relationships between the programmer to implement them. objects in the scene. It also features a scripting environ- ment for 3D objects that allows for the creation of animated 2.2 High level frameworks worlds through time (see Figure 1, C). Squeak Alice uses These frameworks, built on top of graphic libraries, pro- Balloon3D for rendering the scenes[3]. This framework is vide high level abstractions for modeling 3D objects and pro- also not maintained, and because it uses Ballon3D it also ducing graphics. They provide facilities for describing a 3D lacks modern features. scene in terms of objects, promoting separation of concerns (and reuse) for the lighting model, the transformations that ST3D. define spatial relationships between shapes, the camera, and This is a framework for creating 3D applications such as the viewing volume of the scene. Examples are Balloon3D, games, simulations and modelers, with an OpenGL inter- Squeak Alice[5], ST3D, Croquet[7] and Jun. face. It runs on the Dolphin Smalltalk dialect. This commer- We compare the frameworks using several properties listed cial framework was abandoned by the company that created in Table 1. The relevant properties we distinguish are ab- it and it cannot be loaded into the latest Dolphin version. stractions, size, loadable, free commercial usage, and main- tained. Jun. This is a framework for handling multimedia, 2D and 3D • Abstractions refers to the amount of high level con- graphics (see Figure 1, E). Jun is object-oriented and pro- cepts that the framework provides, promoting reusabil- vides good abstractions for modeling 2D and 3D graphics. ity and separation of concerns. For example the CodeCity[9, 11] tool has been built using Jun.