Sample

Schnappinger/aoi/artofillusion.texture.UniformTexture

Human rating uses the original dataset scale.

Human2.99
Lines271

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
15.7Δ 7.4
Scalabrino0.5810–1; higher is more readable
19.2Δ 3.9
Dorn0.0420–1; higher is more readable
27.7Δ 4.6
Mi0.6780–1; higher is more readable
78.5Δ 55.4
LLOC155Logical lines; fewer is more readable
17.3Δ 5.8
DeepSeek V4 Pro16.330–20; mean of three runs
53.1Δ 30.0
GPT-6.1 Sol15.330–20; mean of three runs
30.7Δ 7.6
BTTF0.260–1; higher is more readable
17.5Δ 5.6
Human2.991–4; original rating
23.1

Views

Source code

/* Copyright (C) 1999-2004 by Peter Eastman This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package artofillusion.texture; import artofillusion.*; import artofillusion.object.*; import artofillusion.math.*; import artofillusion.ui.*; import buoy.event.*; import buoy.widget.*; import java.io.*; /** UniformMaterial represents a material whose properties do not vary with position. */ public class UniformTexture extends Texture { public RGBColor diffuseColor, specularColor, transparentColor, emissiveColor; public double roughness, cloudiness; public float transparency, specularity, shininess; public UniformTexture() { // Generate the default color. diffuseColor = new RGBColor(1.0f, 1.0f, 1.0f); specularColor = new RGBColor(1.0f, 1.0f, 1.0f); transparentColor = new RGBColor(1.0f, 1.0f, 1.0f); emissiveColor = new RGBColor(0.0f, 0.0f, 0.0f); transparency = 0.0f; specularity = 0.0f; shininess = 0.0f; roughness = 0.2; cloudiness = 0.0; name = ""; } /** Create a texture which is completely invisible. */ public static UniformTexture invisibleTexture() { UniformTexture tex = new UniformTexture(); tex.diffuseColor.setRGB(0.0f, 0.0f, 0.0f); tex.specularColor.setRGB(0.0f, 0.0f, 0.0f); tex.transparency = 1.0f; return tex; } public static String getTypeName() { return "Uniform"; } public void getTextureSpec(TextureSpec spec) { float frac = (1.0f-transparency)*(1.0f-specularity); spec.diffuse.setRGB(diffuseColor.red*frac, diffuseColor.green*frac, diffuseColor.blue*frac); frac = (1.0f-transparency)*specularity; spec.specular.setRGB(specularColor.red*frac, specularColor.green*frac, specularColor.blue*frac); frac = (1.0f-transparency)*shininess; spec.hilight.setRGB(specularColor.red*frac, specularColor.green*frac, specularColor.blue*frac); spec.transparent.setRGB(transparentColor.red*transparency, transparentColor.green*transparency, transparentColor.blue*transparency); spec.emissive.copy(emissiveColor); spec.roughness = roughness; spec.cloudiness = cloudiness; spec.bumpGrad.set(0.0, 0.0, 0.0); } public void getTransparency(RGBColor trans) { trans.setRGB(transparentColor.red*transparency, transparentColor.green*transparency, transparentColor.blue*transparency); } public void getAverageSpec(TextureSpec spec, double time, double param[]) { getTextureSpec(spec); } /** The only TextureMapping which can be used for a UniformTexture is a UniformMapping. */ public TextureMapping getDefaultMapping(Object3D object) { return new UniformMapping(object, this); } /** Create a duplicate of the texture. */ public Texture duplicate() { UniformTexture m = new UniformTexture(); m.name = name; m.diffuseColor.copy(diffuseColor); m.specularColor.copy(specularColor); m.transparentColor.copy(transparentColor); m.emissiveColor.copy(emissiveColor); m.transparency = transparency; m.specularity = specularity; m.roughness = roughness; m.cloudiness = cloudiness; m.shininess = shininess; return m; } /** Determine whether this texture has a non-zero value anywhere for a particular component. @param component the texture component to check for (one of the *_COMPONENT constants) */ public boolean hasComponent(int component) { switch (component) { case DIFFUSE_COLOR_COMPONENT: return (transparency < 1.0f && specularity < 1.0f && diffuseColor.getMaxComponent() > 0.0); case SPECULAR_COLOR_COMPONENT: return (transparency < 1.0f && specularity > 0.0f && specularColor.getMaxComponent() > 0.0); case TRANSPARENT_COLOR_COMPONENT: return (transparency > 0.0f && transparentColor.getMaxComponent() > 0.0); case HILIGHT_COLOR_COMPONENT: return (transparency < 1.0f && shininess > 0.0f && specularColor.getMaxComponent() > 0.0); case EMISSIVE_COLOR_COMPONENT: return (emissiveColor.getMaxComponent() > 0.0); default: return false; } } /** Allow the user to interactively edit the material. */ public void edit(final BFrame fr, Scene sc) { BTextField nameField = new BTextField(name, 15); final ValueSlider transSlider = new ValueSlider(0.0, 1.0, 100, (double) transparency); final ValueSlider specSlider = new ValueSlider(0.0, 1.0, 100, (double) specularity); final ValueSlider shinSlider = new ValueSlider(0.0, 1.0, 100, shininess); final ValueSlider roughSlider = new ValueSlider(0.0, 1.0, 100, roughness); final ValueSlider clearSlider = new ValueSlider(0.0, 1.0, 100, cloudiness); final Widget diffPatch = diffuseColor.getSample(50, 30); final Widget specPatch = specularColor.getSample(50, 30); final Widget transPatch = transparentColor.getSample(50, 30); final Widget emissPatch = emissiveColor.getSample(50, 30); final UniformTexture newTexture = (UniformTexture) duplicate(); final MaterialPreviewer preview = new MaterialPreviewer(newTexture, null, 200, 160); final ActionProcessor process = new ActionProcessor(); final Runnable renderCallback = new Runnable() { public void run() { preview.render(); } }; diffPatch.addEventLink(MouseClickedEvent.class, new Object() { void processEvent() { new ColorChooser(fr, Translate.text("DiffuseColor"), newTexture.diffuseColor); diffPatch.setBackground(newTexture.diffuseColor.getColor()); process.addEvent(renderCallback); } }); specPatch.addEventLink(MouseClickedEvent.class, new Object() { void processEvent() { new ColorChooser(fr, Translate.text("SpecularColor"), newTexture.specularColor); specPatch.setBackground(newTexture.specularColor.getColor()); process.addEvent(renderCallback); } }); transPatch.addEventLink(MouseClickedEvent.class, new Object() { void processEvent() { new ColorChooser(fr, Translate.text("TransparentColor"), newTexture.transparentColor); transPatch.setBackground(newTexture.transparentColor.getColor()); process.addEvent(renderCallback); } }); emissPatch.addEventLink(MouseClickedEvent.class, new Object() { void processEvent() { new ColorChooser(fr, Translate.text("EmissiveColor"), newTexture.emissiveColor); emissPatch.setBackground(newTexture.emissiveColor.getColor()); process.addEvent(renderCallback); } }); Object valueListener = new Object() { void processEvent() { newTexture.transparency = (float) transSlider.getValue(); newTexture.specularity = (float) specSlider.getValue(); newTexture.shininess = (float) shinSlider.getValue(); newTexture.roughness = roughSlider.getValue(); newTexture.cloudiness = clearSlider.getValue(); process.addEvent(renderCallback); } }; transSlider.addEventLink(ValueChangedEvent.class, valueListener); specSlider.addEventLink(ValueChangedEvent.class, valueListener); shinSlider.addEventLink(ValueChangedEvent.class, valueListener); roughSlider.addEventLink(ValueChangedEvent.class, valueListener); clearSlider.addEventLink(ValueChangedEvent.class, valueListener); ComponentsDialog dlg = new ComponentsDialog(fr, "", new Widget [] { preview, nameField, diffPatch, specPatch, transPatch, emissPatch, transSlider, specSlider, shinSlider, roughSlider, clearSlider}, new String [] {null, Translate.text("Name"), Translate.text("DiffuseColor"), Translate.text("SpecularColor"), Translate.text("TransparentColor"), Translate.text("EmissiveColor"), Translate.text("Transparency"), Translate.text("Specularity"), Translate.text("Shininess"), Translate.text("Roughness"), Translate.text("Cloudiness")}); process.stopProcessing(); if (!dlg.clickedOk()) return; transparency = (float) transSlider.getValue(); specularity = (float) specSlider.getValue(); shininess = (float) shinSlider.getValue(); roughness = roughSlider.getValue(); cloudiness = clearSlider.getValue(); UniformTexture.this.name = nameField.getText(); diffuseColor.copy(newTexture.diffuseColor); specularColor.copy(newTexture.specularColor); transparentColor.copy(newTexture.transparentColor); emissiveColor.copy(newTexture.emissiveColor); int index = sc.indexOf(this); if (index > -1) sc.changeTexture(index); } /** The following two methods are used for reading and writing files. The first is a constructor which reads the necessary data from an input stream. The other writes the object's representation to an output stream. */ public UniformTexture(DataInputStream in, Scene theScene) throws IOException, InvalidObjectException { short version = in.readShort(); if (version < 0 || version > 1) throw new InvalidObjectException(""); name = in.readUTF(); diffuseColor = new RGBColor(in); specularColor = new RGBColor(in); transparentColor = new RGBColor(in); emissiveColor = new RGBColor(in); roughness = in.readDouble(); cloudiness = in.readDouble(); transparency = in.readFloat(); specularity = in.readFloat(); if (version > 0) shininess = in.readFloat(); else shininess = specularity; } public void writeToFile(DataOutputStream out, Scene theScene) throws IOException { out.writeShort(1); out.writeUTF(name); diffuseColor.writeToFile(out); specularColor.writeToFile(out); transparentColor.writeToFile(out); emissiveColor.writeToFile(out); out.writeDouble(roughness); out.writeDouble(cloudiness); out.writeFloat(transparency); out.writeFloat(specularity); out.writeFloat(shininess); } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.13356.201−440.755
Source linesThe number of non-empty source lines.271+108.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.909−7.363

Intercept 8.87 + feature contributions = -330.848 (log-odds).
Score = sigmoid(-330.848) = 0.

Score0.581

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.271−8.559
Indentation frequencyHow rapidly indentation changes from line to line.258+8.187
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.258−5.499
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.269.905+3.363
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.135.974−2.094
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.135.989+1.39
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.096+0.006

Intercept 0.07 + feature contributions = -3.137 (log-odds).
Score = sigmoid(-3.137) = 0.042.

Score0.678
Score155
Run 1

The code is generally readable with clear structure, flat nesting, and well-separated actions. Methods are concise and follow logical organization, with good naming conventions and Javadoc comments. The constructor and serialization methods are straightforward. However, the `edit()` method is significantly longer and more complex than the rest, with nested anonymous classes and multiple responsibilities that reduce readability. It handles UI creation, event wiring, and state updates in one block, making it harder to follow. While overall flow is natural, this method could benefit from decomposition into smaller helper methods. No deeply nested control structures exist, and intent is mostly clear. The score reflects strong readability with minor weakness in the UI editing section.

Run 2

The code is well-structured, with clear separation of concerns across methods for initialization, data access, serialization, and UI. It maintains a mostly flat structure, with only one switch statement and no deeply nested logic. Method names and variable names clearly convey intent, and comments are helpful without being excessive. The code is concise overall, but the `edit` method is long and dense with UI setup, which slightly reduces readability. Action granularity is generally good—one operation per line—except within the UI setup where multiple controls are configured. Reading flow is natural for a typical listener-heavy UI pattern, though the repeated anonymous listener classes are verbose and add length. Overall, the code is highly readable, but the UI method's length and repetition prevent a perfect score.

Run 3

The code is well-structured with clear separation of concerns: field declarations, constructors, core methods, and UI editing logic are logically organized. Nesting is minimal, with only the expected switch-case and event listener nesting. Intent is generally clear from descriptive method and variable names, and Javadoc comments explain non-obvious methods. The code is concise for what it does, avoiding unnecessary verbosity. Action granularity is good—most lines perform a single logical operation, especially in the `getTextureSpec` calculations and `duplicate` method. Reading flow is natural, progressing from simple accessors to more complex serialization and UI methods. Minor deductions: the `edit` method is quite long but remains readable due to consistent patterns; the event listener anonymous classes add some repetition. Overall, this is highly readable, maintainable Java code.

Run 1

Code Structure: Mostly well-organized into focused methods for texture properties, duplication, editing, and serialization, but edit() mixes UI construction, event handling, and state updates. Nesting: Generally shallow; anonymous event-handler classes add moderate nesting without complex branching. Clarity of intent: Descriptive property and method names help, but abbreviated locals, reused frac, misleading UniformMaterial documentation, and material/texture terminology inconsistencies reduce clarity. Code length: Most methods are concise, while edit() is lengthy and repeats color-handler and property-assignment patterns. Action granularity: Statements generally perform one action per line, making changes easy to follow; grouped declarations and dense argument lists are less readable. Reading flow: Initialization, computation, and serialization proceed naturally, with useful spacing and comments. Long arithmetic expressions, parallel dialog arrays, and repetitive listener setup interrupt otherwise straightforward reading.

Run 2

Code Structure: Methods logically separate texture calculations, duplication, component checks, editing, and serialization, although edit mixes UI construction, event handling, and state updates. Nesting: Mostly shallow, with modest additional nesting in anonymous event handlers. Clarity of intent: Descriptive property and method names communicate purpose, but abbreviated locals such as frac and m, misleading material comments, and dense expressions reduce clarity. Code length: Most methods are concise; edit is lengthy and repeats similar color-picker handlers and property assignments. Action granularity: Statements generally perform one action per line, making updates easy to follow. Reading flow: Consistent formatting and straightforward sequential operations support natural reading, but long argument lists, parallel widget/label arrays, and embedded callbacks interrupt the flow.

Run 3

Code Structure: Most responsibilities are separated into focused methods, but edit() combines widget creation, event handling, preview updates, and committing changes. Nesting: Generally shallow; anonymous callback classes introduce moderate nesting without complex control flow. Clarity of intent: Descriptive property and method names make texture behavior understandable, though abbreviated variables, reused frac, and comments referring to UniformMaterial or material reduce precision. Code length: Most methods are concise, but edit() is lengthy and repeats similar color-picker handlers and property assignments. Action granularity: Statements generally perform one action per line, although some expressions and dialog-construction lines are dense. Reading flow: Initialization, texture calculations, duplication, editing, and serialization follow a logical sequence. Consistent formatting and straightforward early returns help, while long lines, positional widget/label arrays, and inconsistent switch indentation interrupt scanning.