Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

try 2
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=23&t=564
Page 1 of 1

Author:  voxi3d [ Mon Dec 30, 2013 2:13 am ]
Post subject:  try 2

I thought it would be much easier to just add voxels at another objects position.

I tried this :
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using Cubiquity;

public class VoxelEdit : MonoBehaviour
{
   public GameObject otherGameObject;
   private ColoredCubesVolume coloredCubesVolume;
   private float targetx;
   private float targety;
   private float targetz;


   // Use this for initialization
   void Start()
   {
      // We'll store a reference to the colored cubes volume so we can interact with it later.
      coloredCubesVolume = gameObject.GetComponent<ColoredCubesVolume>();
      if(coloredCubesVolume == null)
      {
         Debug.LogError("This 'VoxelEdit' script should be attached to a game object with a ColoredCubesVolume component");
      }
   }
   
   // Update is called once per frame
   void Update()
   {
      targetx = (int) otherGameObject.transform.position.x;
      targety = (int) otherGameObject.transform.position.y;
      targetz = (int) otherGameObject.transform.position.z;
      // Bail out if we're not attached to a terrain.
      if(coloredCubesVolume == null)
      {
         return;
      }
      
   

   if(Input.GetMouseButton(1))
         coloredCubesVolume.data.SetVoxel(targetx, targety, targetz, new QuantizedColor(0,0,0,255));
   

   }



   
}


What i am trying to do is just add a single voxel at the OtherGameObject , X Y and Z.

First Cubiquity complains that they are integer values, then when I change to float, it still complains.

Could you please make an example of how to do this?
Please just a working example. One I can run in unity. I am sure other users will appreciate this too.

Thanks in advance.

EDIT sorry this was to be a reply to the other thread. lol, Time to give up and get some sleep.

Author:  David Williams [ Mon Dec 30, 2013 9:28 am ]
Post subject:  Re: try 2

It sounds ok in principle. Is the problem that it won't compile, won't run, nothing happens, it crashes, etc?

Writing QuantizedColor(0,0,0,255) should be fine, but you could also try QuantizedColor(255,255,255,255) in case there is a bug somewhere...

Author:  voxi3d [ Mon Dec 30, 2013 4:45 pm ]
Post subject:  Re: try 2

David Williams wrote:
It sounds ok in principle. Is the problem that it won't compile, won't run, nothing happens, it crashes, etc?

Writing QuantizedColor(0,0,0,255) should be fine, but you could also try QuantizedColor(255,255,255,255) in case there is a bug somewhere...


Hi, the game wont start, it complains about my floats, and then it complains about my integers when I change them from float.

The problem is that I have no working example of how to do this I am afraid. I am not adept at C# yet. My cousin gave me a crash course but I still think in Java for some reason.

I just posted the code in hopes that you guys would see what I am trying to accomplish. Add voxel to another objects X,Y, and Z. My English is not so great.

I can think of quite a few different scenarios where this would be useful. A script we could see working would be nice.

I hope this does not seem like I am trying to con people into making code for me. I can pay for the time.
If someone in the community would like to make some money, I can pay you for a working example too.

* add voxel at a cube’s position
* remove a voxel from a cube position
* re-color existing voxel at cube’s position.

Working C# or Java scripts only please. I will make the scripts free to other users.

I have a feeling I have confused everyone. My English is really bad.

Author:  David Williams [ Mon Dec 30, 2013 7:17 pm ]
Post subject:  Re: try 2

Don't worry, your English is fine ;-)

I quickly tried your code and it is a compile error caused by mismatched types. I don't know JavaScript but I think it doesn't have types in the same way as C#, so this can be confusing. You can fix it by changing the type of the target variables to 'int'. Like so:

Code:
private int targetx;
private int targety;
private int targetz;


It should then compile, but I haven't tested if it works.

Author:  voxi3d [ Mon Dec 30, 2013 7:51 pm ]
Post subject:  Re: try 2

OMG! thank you so much!

I will not have another question ever! it works perfectly!

I have tears in my eyes I am so proud. I was so very close!!

Thank you very much Mr. Williams! You have helped make a dream come true today.

Author:  voxi3d [ Mon Dec 30, 2013 9:33 pm ]
Post subject:  Re: try 2

OK, as promised here is the complete script for others to learn, hack and slash:

Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using Cubiquity;

public class VoxelEdit : MonoBehaviour
{
   public GameObject otherGameObject;
   private ColoredCubesVolume coloredCubesVolume;
   private int targetx;
   private int targety;
   private int targetz;


   // Use this for initialization
   void Start()
   {
      // We'll store a reference to the colored cubes volume so we can interact with it later.
      coloredCubesVolume = gameObject.GetComponent<ColoredCubesVolume>();
      if(coloredCubesVolume == null)
      {
         Debug.LogError("This 'VoxelEdit' script should be attached to a game object with a ColoredCubesVolume component");
      }
   }
   
   // Update is called once per frame
   void Update()
   {
      targetx = (int) otherGameObject.transform.position.x;
      targety = (int) otherGameObject.transform.position.y;
      targetz = (int) otherGameObject.transform.position.z;
      // Bail out if we're not attached to a terrain.
      if(coloredCubesVolume == null)
      {
         return;
      }
      
   

   if(Input.GetMouseButton(1))
         coloredCubesVolume.data.SetVoxel(targetx, targety, targetz, new QuantizedColor(0,0,0,255));
   

   }



   
}



Attach it to the ColoredCubesVolume game object.
Then you can add your "cursor" object to the script in the inspector (put where says "otherGameObject").

The "cursor" object is where you want the voxels to draw, it can be a cube,empty, whatever.

I just parented a cube to a default unity FirstPersonController object. Then when player presses mouse button 2 (right click) a black voxel is added.

Hope this helps some one! :)

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/