Index  | Recent Threads  | List Attachments  | Search
 Welcome Guest  |  Register  |  Login
Login Name  Password
 

Sweet Home 3D Forum



No member browsing this thread
Thread Status: Active
Total posts in this thread: 5
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 5161 times and has 4 replies Next Thread
chicosRV
Newbie




Joined: May 25, 2012
Post Count: 14
Status: Offline
Reply to this Post  Reply with Quote 
use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

hello

i need to make a plugin to export the furniture in separated obj files, i have to use private elements of the classes HomePane and HomeController. how can i do this?????
[Jun 22, 2012, 3:22:38 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9420
Status: Offline
Reply to this Post  Reply with Quote 
Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

Which elements do you need?
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
[Jun 22, 2012, 4:16:32 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
chicosRV
Newbie




Joined: May 25, 2012
Post Count: 14
Status: Offline
Reply to this Post  Reply with Quote 
Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

this is what i have done

i modified the original code of the methods export to obj(it originally exported everything in one obj)

but what i really need is to made that function in a plugin

when a took the code for made the pluggin there were a lot of element that get selected like error

the plugin class only have the home and the userPreferences


this is the code

class Home Controller

public void exportToOBJ() {
final String objName = getView().showExportToOBJDialog(this.home.getName());
final String dir = reduceToRoot(objName);
HomePane.dir = dir;

//Count Furniture//

countFurniture();
writeXMLEden3D("ss");


if (objName != null) {

// Export 3D view in a threaded task
Callable<Void> exportToObjTask = new Callable<Void>() {
public Void call() throws RecorderException {
getView().exportToOBJ(HomePane.dir);
return null;
}
};
ThreadedTaskController.ExceptionHandler exceptionHandler =
new ThreadedTaskController.ExceptionHandler() {
public void handleException(Exception ex) {
if (!(ex instanceof InterruptedRecorderException)) {
if (ex instanceof RecorderException) {
String message = preferences.getLocalizedString(
HomeController.class, "exportToOBJError", objName);
getView().showError(message);
} else {
ex.printStackTrace();
}
}
}
};
new ThreadedTaskController(exportToObjTask,
this.preferences.getLocalizedString(HomeController.class, "exportToOBJMessage"), exceptionHandler,
this.preferences, this.viewFactory).executeTask(getView());
}

}







class HomePane

public static void exportHomeToFile(Home home, String objFile, String header) throws RecorderException {
OBJWriter writer = null;
boolean exportInterrupted = false;

String[] names = new String[HomePane.counter];
names[0] = "Room";
int c=1;
for(HomePieceOfFurniture piece : home.getFurniture()) {
if(piece.isVisible()) {
names[c] = piece.getName();
c++;
}

}



for(int j=0 ; j < HomePane.counter; j++ ) {
try {
HomePane.objName = names[j];
writer = new OBJWriter(objFile+HomePane.objName+".obj", header, -1);

List<Selectable> emptySelection = Collections.emptyList();

home.setSelectedItems(emptySelection);



if (HomePane.objName.equals("Room"))
{


if (home.getWalls().size() > 0) {
// Create a not alive new ground to be able to explore its coordinates without setting capabilities
Rectangle2D homeBounds = getExportedHomeBounds(home);
Ground3D groundNode = new Ground3D(home,
(float)homeBounds.getX(), (float)homeBounds.getY(),
(float)homeBounds.getWidth(), (float)homeBounds.getHeight(), true);
writer.writeNode(groundNode, "ground");
}
}

// Write 3D walls
int i;


// The first time, we want to export the only the walls and the room
if (HomePane.objName.equals("Room"))
{
i = 0;

for (Wall wall : home.getWalls()) {
// Create a not alive new wall to be able to explore its coordinates without setting capabilities
Wall3D wallNode = new Wall3D(wall, home, true, true);
writer.writeNode(wallNode, "wall_" + ++i);
}

// Write 3D rooms
i = 0;
for (Room room : home.getRooms()) {

// Create a not alive new room to be able to explore its coordinates without setting capabilities
Room3D roomNode = new Room3D(room, home, false, true, true);
writer.writeNode(roomNode, "room_" + ++i);
}
}

i = 0;

if (!HomePane.objName.equals("Room"))
{

//Write 3D furniture
for (HomePieceOfFurniture piece : home.getFurniture()) {
if (piece.isVisible() && HomePane.objName.equals(piece.getName())) {

// System.out.printf(objFile + "\n");
// Create a not alive new piece to be able to explore its coordinates without setting capabilities
// I set as home = null
HomePieceOfFurniture3D pieceNode = new HomePieceOfFurniture3D(piece, home, true, true);
writer.writeNode(pieceNode);
}
}
}
}
catch (InterruptedIOException ex) {
exportInterrupted = true;
throw new InterruptedRecorderException("Export to " + objFile + " interrupted");
} catch (IOException ex) {
throw new RecorderException("Couldn't export to OBJ in " + objFile, ex);
} finally {
if (writer != null) {

try {
writer.close();
// Delete the file if exporting is interrupted
if (exportInterrupted) {
new File(objFile).delete();
}
} catch (IOException ex) {
throw new RecorderException("Couldn't export to OBJ in " + objFile, ex);
}
}
}



}
}

[Jun 22, 2012, 5:04:16 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9420
Status: Offline
Reply to this Post  Reply with Quote 
Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

I think you missed the following point:
Version 3.5 gave access to the HomeController instance from a plug-in instance. Then, from the HomeController instance you can access to the other controllers and their views if necessary.

If exportToOBJ method doesn't perform like you want, I don't see the problem to write your own method in your plug-in. But if you want to change the behavior of the existing exportToOBJ method, you'll have to create a derived version of Sweet Home 3D, not a plug-in.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
[Jun 22, 2012, 7:00:27 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
chicosRV
Newbie




Joined: May 25, 2012
Post Count: 14
Status: Offline
Reply to this Post  Reply with Quote 
Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

thanks for your help i already downloaded the 3.5 version but i could finally made the plugin for the 3.3 version(it was a very important school homework and i couldn't use other version) but at the end i could made it(i don't wanted to change the original exportToObj, i only wanted to test the method a made) my pupouse was to made a export to open it in another application

by the way the orientation of a furniture is given by an angle , respect to what axe(x,y or z) it is,beacause i need to convert that angle in a vector, it;s that posible???
[Jun 26, 2012, 9:42:15 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread

  Get Sweet Home 3D at SourceForge.net. Fast, secure and Free Open Source software downloads  
© Copyright 2024 Space Mushrooms - All rights reserved