Skip to content

Adding teapot geometry as a preview geometry #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.gde.materials;

Expand All @@ -19,6 +46,7 @@
import com.jme3.math.Vector3f;
import com.jme3.renderer.RendererException;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Quad;
import com.jme3.scene.shape.Sphere;
Expand All @@ -40,6 +68,7 @@ public class MaterialPreviewRenderer implements SceneListener {
private Geometry sphere;
private Geometry box;
private Geometry quad;
private Geometry teapot;
private Geometry currentGeom;
private Material currentMaterial;
private boolean init = false;
Expand All @@ -51,7 +80,8 @@ public enum DisplayType {

Sphere,
Box,
Quad
Quad,
Teapot
}

public MaterialPreviewRenderer(JLabel label) {
Expand All @@ -78,13 +108,20 @@ private void init() {
quad = new Geometry("previewQuad", quadMesh);
quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));
MikktspaceTangentGenerator.generate(quad);


teapot = (Geometry) SceneApplication.getApplication().getAssetManager()
.loadModel("Models/Teapot/Teapot.obj");
teapot.scale(3.5f);
teapot.rotate(FastMath.PI, -FastMath.QUARTER_PI * 0.5f, -0.0f);
teapot.setLocalTranslation(new Vector3f(-0.5f, 1.75f, 0));
MikktspaceTangentGenerator.generate(teapot);

currentGeom = sphere;
init = true;
}

@SuppressWarnings("unchecked")
public void showMaterial(final ProjectAssetManager assetManager,final String materialFileName) {
public void showMaterial(final ProjectAssetManager assetManager, final String materialFileName) {
if (!init) {
init();
}
Expand Down Expand Up @@ -227,6 +264,8 @@ public void switchDisplay(DisplayType type) {
case Quad:
currentGeom = quad;
break;
case Teapot:
currentGeom = teapot;
}
showMaterial(currentMaterial);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ ColorPanel.jLabel3.text=\ g :
ColorPanel.jLabel2.text=\ r :
ColorPanel.bLabel.text=0.2545
TexturePanel.texturePreview.toolTipText=Texture
MaterialPreviewWidget.teapotButton.toolTipText=Preview material on a teapot
MaterialPreviewWidget.teapotButton.text=
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[40, 40]"/>
</Property>
<Property name="pressedIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Property name="selectedIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="Icons.planeOn" type="code"/>
</Property>
<Property name="verticalTextPosition" type="int" value="3"/>
Expand Down Expand Up @@ -192,6 +192,41 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="sphereButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToggleButton" name="teapotButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="toggleButtonGroup"/>
</Property>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="Icons.teapotOff" type="code"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/materials/multiview/widgets/Bundle.properties" key="MaterialPreviewWidget.teapotButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/materials/multiview/widgets/Bundle.properties" key="MaterialPreviewWidget.teapotButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[40, 40]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[40, 40]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[40, 40]"/>
</Property>
<Property name="selectedIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="Icons.teapotOn" type="code"/>
</Property>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="teapotButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToolBar$Separator" name="jSeparator1">
</Component>
<Component class="javax.swing.JToggleButton" name="togglePbrEnvButton">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* MaterialPreviewWidget.java
*
Expand Down Expand Up @@ -73,6 +99,7 @@ private void initComponents() {
cubeButton = new javax.swing.JToggleButton();
planeButton = new javax.swing.JToggleButton();
sphereButton = new javax.swing.JToggleButton();
teapotButton = new javax.swing.JToggleButton();
jSeparator1 = new javax.swing.JToolBar.Separator();
togglePbrEnvButton = new javax.swing.JToggleButton();

Expand All @@ -86,7 +113,6 @@ private void initComponents() {
previewLabel.setMinimumSize(new java.awt.Dimension(200, 200));

jToolBar1.setOrientation(javax.swing.SwingConstants.VERTICAL);
jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);
jToolBar1.setMaximumSize(new java.awt.Dimension(80, 50));
jToolBar1.setMinimumSize(new java.awt.Dimension(80, 50));
Expand Down Expand Up @@ -120,7 +146,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
planeButton.setMaximumSize(new java.awt.Dimension(40, 40));
planeButton.setMinimumSize(new java.awt.Dimension(40, 40));
planeButton.setPreferredSize(new java.awt.Dimension(40, 40));
planeButton.setPressedIcon(Icons.planeOn);
planeButton.setSelectedIcon(Icons.planeOn);
planeButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
planeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Expand Down Expand Up @@ -148,6 +174,25 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
jToolBar1.add(sphereButton);

toggleButtonGroup.add(teapotButton);
teapotButton.setIcon(Icons.teapotOff);
teapotButton.setText(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.teapotButton.text")); // NOI18N
teapotButton.setToolTipText(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.teapotButton.toolTipText")); // NOI18N
teapotButton.setFocusable(false);
teapotButton.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
teapotButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
teapotButton.setMaximumSize(new java.awt.Dimension(40, 40));
teapotButton.setMinimumSize(new java.awt.Dimension(40, 40));
teapotButton.setPreferredSize(new java.awt.Dimension(40, 40));
teapotButton.setSelectedIcon(Icons.teapotOn);
teapotButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
teapotButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
teapotButtonActionPerformed(evt);
}
});
jToolBar1.add(teapotButton);
jToolBar1.add(jSeparator1);

togglePbrEnvButton.setIcon(Icons.lightOff);
Expand Down Expand Up @@ -207,13 +252,18 @@ private void togglePbrEnvButtonActionPerformed(java.awt.event.ActionEvent evt) {
matRenderer.refreshOnly();
}//GEN-LAST:event_togglePbrEnvButtonActionPerformed

private void teapotButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_teapotButtonActionPerformed
matRenderer.switchDisplay(MaterialPreviewRenderer.DisplayType.Teapot);
}//GEN-LAST:event_teapotButtonActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JToggleButton cubeButton;
private javax.swing.JToolBar.Separator jSeparator1;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JToggleButton planeButton;
private javax.swing.JLabel previewLabel;
private javax.swing.JToggleButton sphereButton;
private javax.swing.JToggleButton teapotButton;
private javax.swing.ButtonGroup toggleButtonGroup;
private javax.swing.JToggleButton togglePbrEnvButton;
// End of variables declaration//GEN-END:variables
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.gde.materials.multiview.widgets.icons;

import javax.swing.ImageIcon;
import org.openide.util.ImageUtilities;

/**
*
* Lists all icons used by the Material Editor
* @author rickard
*/
public class Icons {
Expand All @@ -18,8 +45,10 @@ public class Icons {
public static final String CUBE_OFF = ICONS_PATH + "cube.svg";
public static final String SPHERE_OFF = ICONS_PATH + "sphere.svg";
public static final String PLANE_OFF = ICONS_PATH + "plane.svg";
public static final String TEAPOT_OFF = ICONS_PATH + "teapot-off.svg";
public static final String CUBE_ON = ICONS_PATH + "cube-on.svg";
public static final String SPHERE_ON = ICONS_PATH + "sphere-on.svg";
public static final String TEAPOT_ON = ICONS_PATH + "teapot-on.svg";
public static final String PLANE_ON = ICONS_PATH + "plane-on.svg";
public static final String LIGHT_ON = ICONS_PATH + "light-bulb-on.svg";
public static final String LIGHT_OFF = ICONS_PATH + "light-bulb-off.svg";
Expand All @@ -32,12 +61,16 @@ public class Icons {
ImageUtilities.loadImageIcon(SPHERE_OFF, false);
public static final ImageIcon plane =
ImageUtilities.loadImageIcon(PLANE_OFF, false);
public static final ImageIcon teapotOff =
ImageUtilities.loadImageIcon(TEAPOT_OFF, false);
public static final ImageIcon cubeOn =
ImageUtilities.loadImageIcon(CUBE_OFF, false);
ImageUtilities.loadImageIcon(CUBE_ON, false);
public static final ImageIcon sphereOn =
ImageUtilities.loadImageIcon(SPHERE_OFF, false);
ImageUtilities.loadImageIcon(SPHERE_ON, false);
public static final ImageIcon planeOn =
ImageUtilities.loadImageIcon(PLANE_OFF, false);
ImageUtilities.loadImageIcon(PLANE_ON, false);
public static final ImageIcon teapotOn =
ImageUtilities.loadImageIcon(TEAPOT_ON, false);
public static final ImageIcon lightOn =
ImageUtilities.loadImageIcon(LIGHT_ON, false);
public static final ImageIcon lightOff =
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading